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

"Type Mismatch" trying to reference and export Excel chart

Status
Not open for further replies.

aregan1

Programmer
Feb 12, 2002
46
US
I'm trying to use VB to export an Excel chart (not an embedded chart) as a .gif file. I get a "type mismatch" error when just trying to reference the chart, before the actual export step. A few samples of the code I've tried follow:

[tt] Sheets(SheetName).Export FileName:=Fname, FilterName:="GIF"[/tt]

[tt] Charts(SheetName).Export FileName:=Fname, FilterName:="GIF"[/tt]

[tt] Sheets(SheetName).Activate
ActiveSheet.Export FileName:=Fname, FilterName:="GIF"[/tt]

Can anyone help me? Please keep any responses simple, as I am fairly new to VB coding. Thanks a lot... :->



 
Hi,
Here's a solution...
Code:
ActiveWorkbook.Charts(1) _
        .Export _
        Filename:="c:\current_sales.gif", FilterName:="GIF"
hope this helps :) Skip,
metzgsk@voughtaircraft.com
 
Thanks, Skip...

Your suggestion works if typed in as is. However, my user will be typing the name of the chart that he wants to save, and I want to use the name of the chart as the index to Charts(). When I use the chart name, I get the "type mismatch" error. But when I hardcode an index number, it works.

How can I reference the chart that I want with only the chart name, and not the number?

Thanks for your help once again...

Anita
 
Maybe the following will help, where Chart 1 is the name of the chart :
Code:
ActiveSheet.ChartObjects("Chart 1").Chart.Export _
    FileName:="E:\current_sales.gif", _
        FilterName:="Gif"
AC
 
Thanks AC, but when I try your suggestion, instead of a "type mismatch" error, I get "Unable to get the ChartObjects property of the Worksheet"...
 
Aregean1,
Need to see ALL your code.

I can specify a chart name and export it. The code assumes that the ActiveWorkbook contains the chart. It works. :) Skip,
metzgsk@voughtaircraft.com
 
Skip -

Thanks for you offer to help, but I figured out my problem! I had the following code:

Code:
Charts(SheetName).Export  FileName:=Fname, FilterName:="GIF"

SheetName is the name of the textbox where the user would input the name of the chart he wanted to save. To fix it, I changed it to:

Code:
Charts(SheetName.text).Export  FileName:=Fname, FilterName:="GIF"

and it worked just fine!!!! Something so simple...

Thanks again... :->

- Anita
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top