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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exporting a chart. EXCEL VBA. error help

Status
Not open for further replies.

laythss

Technical User
Oct 27, 2004
10
US
I am having trouble getting this code to work. I have an open
workbook, with an active worksheet named "Sheet1" which has an embeded
chart (object) here is my code that runs when you press the
CommandButton1 on the user form I created:

Private Sub CommandButton1_Click()
Call Create_GIF
Image1.Picture = LoadPicture("c:\Mychart.gif")
End Sub

Sub Create_GIF()
With Worksheets("Sheet1").ChartObjects(1).Chart
.HasTitle = True
.ChartTitle.Text = "1995 Rainfall Totals by Month"
.Export Filename:="layth.gif", FilterName:="GIF"
End With

The code works until the .export line, the Chart get a new name as I
specefied in the line .ChartTitle.......
but I recieve the following error message:
RUN TIME ERROR '1004':
Application-defined or Object-defined error

Where am I going wrong here. I tried changing the filename to "layth"
, I also tried using jpg instead, but nothing worked.

Can someone help PLEASE.
 

I recreated your scenerio with a command button and an image in a userform. Your code runs to completion, with the exception of the fielname inconsistency.

I am at a loss. Is there anything missing? Where do you have the Create_GIF sub stored?

Skip,
[sub]
[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue][/sub]

 
Skip, do you mean it worked?
What version of excel are you using.
Ok I think the problem is not in the code but in my version of excel
I have
Excel 2003 (11.5612.6360)

I tried using the J-Walk Chart tools add-in and it produced the same exact error
So I looked around and I found a thread but NO solution. here is a point to that thread :

Is there a solution to this problem???
Layth
 
Excel 2000

That link seems to indicate that Shared Components fails when a later version of Office is loaded over a previous one.

Have you searched for this error/solution?



Skip,
[sub]
[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue][/sub]
 
yes but I was not able to get any info.
In addition I uninstalled my 2000 before installing my 2003, i remember this bec. I had terrible time moving my outlook information whereas if you choose to upgrade it does it automatically.
I read somewhere else that maybe selecting the chart before doing this might help (it was for a different problem but with the same error) so I modefied my code to this:

Sub Create_GIF()
With Worksheets("Sheet1").ChartObjects(1).Chart
.HasTitle = True
.ChartTitle.Text = "1995 Rainfall Totals by Month"

End With

Worksheets("Sheet1").ChartObjects(1).Chart.Activate
Worksheets("Sheet1").ChartObjects(1).Chart.Export Filename:="layth.gif", FilterName:="GIF"

End Sub

Q: is the line :
Worksheets("Sheet1").ChartObjects(1).Chart.Activate
correct, or I am not supposed to use Activate like this
Now I recieve :

error '1004'
activate method for chart class failed

Any ideas?
 


Why do you want to Activate the Chart? It is not necessary to do so.

How Can I Make My Code Run Faster? faq707-4105

But to answer the question, It could be that the SHEET was not the activesheet. You would need to activate the sheet before activating or selecting any object that is in the sheet.


Skip,
[sub]
[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue][/sub]

 
Thanks skip that was just a lame attempt on my behalf, to try to find the problem, but I found something else while playing around:

Ok here is my last find:

The code will run as long as I use a tiff format
here is my new code:
Code:
Private Sub CommandButton1_Click()
   Call Create_GIF
    Image1.Picture = LoadPicture("mychart.gif")
    
    
End Sub
Sub Create_GIF()
With Worksheets("Sheet1").ChartObjects(1).Chart
    .HasTitle = True
    .ChartTitle.Text = "1995 Rainfall Totals by Month"
    .Export Filename:="mychart.tiff"
    
End With

It is great that it is working, but my problem is the following now:
I was trying to make the form according to the selection of the user (combobox selection) display -ON the form- a chart for that selection
so It would display it in Image1 (an image control on my form) But the image control cannot take a tiff file.
oh yes I tried fooling the program but it is aprogram so it was not fooled, my attempt of changing the export line to the following:
Code:
 .Export Filename:="mychart.gif", FilterName:="TIF"
the code works again here but I get an error '481' Invalid Picture

Any ideas or help?
 


I also used a JPEG filter to export and load a .jpg file

Skip,
[sub]
[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue][/sub]

 
Ok, I think I got the thing sort of fixed. I found that I had office 2000 still showing under my programs when I add/remove. so I uninstalled all of them and reinstalled Office 2003 in full. Now both .jpg and .gif work but .tiff does not???? and since I do not care about the tiff I won't have a problem. YET the problem will be if I send this file to someone who has 2003 and ends up having the same problem as I did?????
I guess I will post a new thread of a way to capture that error and possibly end the program peacefully with no problems, and once they contact me I would have to try to solve the problem as I did.

Layth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top