Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting Excel Charts 1

Status
Not open for further replies.

twooly

MIS
Feb 22, 2004
122
US
Hopefully someone can help me out with this one. Basicly I am trying to export all the charts on one sheet. Here is my code but I am getting "Expected Statement" on Line 8 (mychart.Export Filename:="c:\charts\chart_" & i & ".gif", FilterName:="GIF")

Thanks for the help

Code

Set objXL = WScript.CreateObject("Excel.Application")
objXL.Visible = False
objXL.Workbooks.Open("Sheet.xls")
Set Worksheet = objXL.Sheets(1)

For i = 1 To ActiveSheet.ChartObjects.Count
Set mychart = ActiveSheet.ChartObjects(i).Chart
mychart.Export Filename:="c:\charts\chart_" & i & ".gif", FilterName:="GIF"
Next i
 
VBScript doesn't support named parameters, only positional.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Replace this:
mychart.Export Filename:="c:\charts\chart_" & i & ".gif", FilterName:="GIF"
By this:
mychart.Export "c:\charts\chart_" & i & ".gif", "GIF"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Same thing. You think the command should all be in one quote? How do you escape quotes?
 
I tried this too with the same results

mychart.Export """c:\charts\chart_" & i & ".gif""" & "," & """GIF"""

Any other ideas.
 
And replacing the 2 occurrences of ActiveSheet by Worksheet ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Got it figured out. Thanks for the help.

Set objXL = WScript.CreateObject("Excel.Application")
objXL.Visible = False
objXL.Workbooks.Open("Sheet.xls")
objXL.Worksheets(1).Activate

For i = 1 To AobjXL.Worksheets(1).ChartObjects.Count
Set mychart = objXL.Worksheets(1).ChartObjects(i).Chart
mychart.Export "c:\charts\chart_" & i & ".gif", "GIF"
Next i
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top