Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am new to developing in VBA for Excel. I'd appreciate any tips on
how to fix this bug, as I believe I am on the right track but something I can't quite see is incorrect. Thanks in advance. I have a workbook with 7 sheets. Let's say on worksheet 5 there are 5 charts. On Worksheet 6 I have 5 option buttons, and for each button that I select I want to display a particular chart. I have been able to successfully loop through my chart objects and verify that I have 5, yet when I try to export each of them I get the following error: Run-time error '1004' Application-defined or object-defined error Below is my code sample of just trying to export one chart. The last line of the code is where I get an error. Any help will be greatly appreciated. Private Sub OptionButton1_Click() Dim strGifFileName As String Dim CurrentChart As Chart Dim index As Integer index = 1 Set CurrentChart = Worksheets(6).ChartObjects(index).Chart strGifFileName = "C:\My Documents\" & "MyChart" & index & ".gif" CurrentChart.Export fileName:=strGifFileName, FilterName:="GIF" End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Julia,
What if you do not use "index" as the name of your variable ? NickHK wrote in message oups.com... I am new to developing in VBA for Excel. I'd appreciate any tips on how to fix this bug, as I believe I am on the right track but something I can't quite see is incorrect. Thanks in advance. I have a workbook with 7 sheets. Let's say on worksheet 5 there are 5 charts. On Worksheet 6 I have 5 option buttons, and for each button that I select I want to display a particular chart. I have been able to successfully loop through my chart objects and verify that I have 5, yet when I try to export each of them I get the following error: Run-time error '1004' Application-defined or object-defined error Below is my code sample of just trying to export one chart. The last line of the code is where I get an error. Any help will be greatly appreciated. Private Sub OptionButton1_Click() Dim strGifFileName As String Dim CurrentChart As Chart Dim index As Integer index = 1 Set CurrentChart = Worksheets(6).ChartObjects(index).Chart strGifFileName = "C:\My Documents\" & "MyChart" & index & ".gif" CurrentChart.Export fileName:=strGifFileName, FilterName:="GIF" End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The index was just for testing purposes - I want to just save Chart 1
to a gif file for now. I plan to loop through my chart objects and according to index save them to the appropriate file names. Can you clarify why you mention not using the index variable? My error is on the line: CurrentChart.Export fileName:=strGifFileName, FilterName:="GIF" |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
HI,
The reason Nick says this is because he thinks Index is a reserved word in VB....I dunno whether it is or not but If I change the name of the variable it works for me....having said that it works with index too...iwould steer clear of words like that for variables tho'.....the only other thing I can think of is the directory doesn't exist.. OJ |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks to you both. I changed the variable name to chart_index. And
that did not help, but apparently there is an issue with the way I have defined the location to save the file: strGifFileName = "C:\My Documents\" & "MyChart" & chart_index & ".gif" When I changed it to just C:\ it worked. I would prefer My Documents. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
There's usually no
C:\My Documents folder, unless you spesifically created one yourself. My Documents is a friendly name for somewhere else, real path depending on who's using the computer at the moment. HTH. Best wishes Harald skrev i melding ups.com... Thanks to you both. I changed the variable name to chart_index. And that did not help, but apparently there is an issue with the way I have defined the location to save the file: strGifFileName = "C:\My Documents\" & "MyChart" & chart_index & ".gif" When I changed it to just C:\ it worked. I would prefer My Documents. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Another thought - if My Documents is your Default File Location (Tools
Options General) Sub test() Dim strGifFileName As String Dim sDefPath As String Dim sPathSep As String Dim chart_index As Long sPathSep = Application.PathSeparator sDefPath = Application.DefaultFilePath If Right$(sDefPath, 1) < sPathSep Then sDefPath = sDefPath & sPathSep End If chart_index = 3 strGifFileName = sDefPath & "MyChart" & chart_index & ".gif" Debug.Print strGifFileName End Sub Regards, Peter T Thanks to you both. I changed the variable name to chart_index. And that did not help, but apparently there is an issue with the way I have defined the location to save the file: strGifFileName = "C:\My Documents\" & "MyChart" & chart_index & ".gif" When I changed it to just C:\ it worked. I would prefer My Documents. |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Julia,
Depending on your set up, I bet the path you mean is more like: C:\Documents and Settings\<User Name\My Documents\MyChart" & index & ".gif" Yes, as OJ says, IMHO it is better to avoid such variable names that are used by VB, even if it is not reserved. NickHK wrote in message ups.com... The index was just for testing purposes - I want to just save Chart 1 to a gif file for now. I plan to loop through my chart objects and according to index save them to the appropriate file names. Can you clarify why you mention not using the index variable? My error is on the line: CurrentChart.Export fileName:=strGifFileName, FilterName:="GIF" |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
exporting chart | Excel Discussion (Misc queries) | |||
I get COMException while exporting chart on IIS 6.0. | Charts and Charting in Excel | |||
Exporting CSV file to unicode .txt file - " around strings | Excel Discussion (Misc queries) | |||
Exporting chart to GIF file | Excel Programming | |||
Trouble exporting chart to htm file - need help | Excel Programming |