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
|
|||
|
|||
![]()
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" |
#8
![]()
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. |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Harald,
XL (or is it Win XP?) correctly expands c:My Documents (when used with no intervening reverse-slash). -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions In article , lid says... 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. |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Tushar
Not here they do, norwegian WinXP, various Excel versions. So at best it's an unstable solution for use in controlled environments. Environ works well (but not in the 9x windows family). Best wishes Harald "Tushar Mehta" skrev i melding om... Hi Harald, XL (or is it Win XP?) correctly expands c:My Documents (when used with no intervening reverse-slash). -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions |
#11
![]()
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. |
#12
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Harald,
Yeah, I too was surprised when I read that code somewhere. Was about to post a "That's not going to work when I tested it. To my suprise, it worked just fine." I guess outside of the two suggestions I provided, the only other choice for the OP would be to use the appropriate Windows API to get the user name and go from there. -- Regards, Tushar Mehta www.tushar-mehta.com Multi-disciplinary business expertise + Technology skills = Optimal solution to your business problem Recipient Microsoft MVP award 2000-2005 In article , lid says... Hi Tushar Not here they do, norwegian WinXP, various Excel versions. So at best it's an unstable solution for use in controlled environments. Environ works well (but not in the 9x windows family). Best wishes Harald "Tushar Mehta" skrev i melding om... Hi Harald, XL (or is it Win XP?) correctly expands c:My Documents (when used with no intervening reverse-slash). -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions |
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 |