Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default VBA to save a chart as a GIF

I have the following snippet of code to save a chart as a GIF. What am I
missing?

For Each WS In aWB.Worksheets
For Each ChtObj In WS.ChartObjects

If ChtObj.Name = "myName.gif" Then
fname = aWB.Path & "\myFileName.gif"
WS.Select
ChtObj.Select
ChtObj.Export Filename:=fname, FilterName:="GIF"
End If
Next ChtObj
Next WS


Thanks,
Barb Reinhardt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default VBA to save a chart as a GIF

If the chartobject's name is in fact "myName.gif", this should work. No need
to select worksheet or chart object, but you need to export the chart, not
the parent chartobject.

For Each WS In aWB.Worksheets
For Each ChtObj In WS.ChartObjects

If ChtObj.Name = "myName.gif" Then
fname = aWB.Path & "\myFileName.gif"
ChtObj.Chart.Export Filename:=fname, FilterName:="GIF"
End If
Next ChtObj
Next WS

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Barb Reinhardt" wrote in message
...
I have the following snippet of code to save a chart as a GIF. What am I
missing?

For Each WS In aWB.Worksheets
For Each ChtObj In WS.ChartObjects

If ChtObj.Name = "myName.gif" Then
fname = aWB.Path & "\myFileName.gif"
WS.Select
ChtObj.Select
ChtObj.Export Filename:=fname, FilterName:="GIF"
End If
Next ChtObj
Next WS


Thanks,
Barb Reinhardt




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default VBA to save a chart as a GIF

Thanks for helping to identify my two problems. In error, I had checked for
the chart name with a .gif at the end. I also needed to change

ChtObj.Export Filename:=fname, FilterName:="GIF"

to

ChtObj.Chart.Export Filename:=fname, FilterName:="GIF"

Thanks again Jon,

Barb


"Jon Peltier" wrote:

If the chartobject's name is in fact "myName.gif", this should work. No need
to select worksheet or chart object, but you need to export the chart, not
the parent chartobject.

For Each WS In aWB.Worksheets
For Each ChtObj In WS.ChartObjects

If ChtObj.Name = "myName.gif" Then
fname = aWB.Path & "\myFileName.gif"
ChtObj.Chart.Export Filename:=fname, FilterName:="GIF"
End If
Next ChtObj
Next WS

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Barb Reinhardt" wrote in message
...
I have the following snippet of code to save a chart as a GIF. What am I
missing?

For Each WS In aWB.Worksheets
For Each ChtObj In WS.ChartObjects

If ChtObj.Name = "myName.gif" Then
fname = aWB.Path & "\myFileName.gif"
WS.Select
ChtObj.Select
ChtObj.Export Filename:=fname, FilterName:="GIF"
End If
Next ChtObj
Next WS


Thanks,
Barb Reinhardt





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default VBA to save a chart as a GIF

Hey Jon, I have another related question. How would I save workbook level
named range "YTD_Summary" as a GIF image?

Thanks again,
Barb

"Jon Peltier" wrote:

If the chartobject's name is in fact "myName.gif", this should work. No need
to select worksheet or chart object, but you need to export the chart, not
the parent chartobject.

For Each WS In aWB.Worksheets
For Each ChtObj In WS.ChartObjects

If ChtObj.Name = "myName.gif" Then
fname = aWB.Path & "\myFileName.gif"
ChtObj.Chart.Export Filename:=fname, FilterName:="GIF"
End If
Next ChtObj
Next WS

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Barb Reinhardt" wrote in message
...
I have the following snippet of code to save a chart as a GIF. What am I
missing?

For Each WS In aWB.Worksheets
For Each ChtObj In WS.ChartObjects

If ChtObj.Name = "myName.gif" Then
fname = aWB.Path & "\myFileName.gif"
WS.Select
ChtObj.Select
ChtObj.Export Filename:=fname, FilterName:="GIF"
End If
Next ChtObj
Next WS


Thanks,
Barb Reinhardt





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default VBA to save a chart as a GIF

To export a range, you need to copy it into a blank chart, and export the
blank chart. Harald Staff wrote and David McRitchie posted an XL2GIF routine
that does this:

http://www.mvps.org/dmcritchie/excel/xl2gif.htm

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Barb Reinhardt" wrote in message
...
Hey Jon, I have another related question. How would I save workbook
level
named range "YTD_Summary" as a GIF image?

Thanks again,
Barb

"Jon Peltier" wrote:

If the chartobject's name is in fact "myName.gif", this should work. No
need
to select worksheet or chart object, but you need to export the chart,
not
the parent chartobject.

For Each WS In aWB.Worksheets
For Each ChtObj In WS.ChartObjects

If ChtObj.Name = "myName.gif" Then
fname = aWB.Path & "\myFileName.gif"
ChtObj.Chart.Export Filename:=fname, FilterName:="GIF"
End If
Next ChtObj
Next WS

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Barb Reinhardt" wrote in
message
...
I have the following snippet of code to save a chart as a GIF. What am
I
missing?

For Each WS In aWB.Worksheets
For Each ChtObj In WS.ChartObjects

If ChtObj.Name = "myName.gif" Then
fname = aWB.Path & "\myFileName.gif"
WS.Select
ChtObj.Select
ChtObj.Export Filename:=fname, FilterName:="GIF"
End If
Next ChtObj
Next WS


Thanks,
Barb Reinhardt









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default VBA to save a chart as a GIF

Here's another 'bare bones' one ( I wasn't aware of the link to Harold
Staff's as posted by Jon)

Sub RangeToGif(rng As Range, sFile As String)
Dim sName As String

rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture

With ActiveSheet.ChartObjects.Add(0, 0, 100, 100)
.Width = rng.Width + 4
.Height = rng.Height + 4
'.Chart.ChartArea.Border.LineStyle = xlNone
.Chart.Pictures.Paste
' to do: check if sFile already exists etc
.Chart.Export sFile ' best to omit FilterName for default Gif

End With
' comment this for testing
ActiveSheet.ChartObjects(ActiveSheet.ChartObjects. Count).Delete

End Sub

Sub test()
Dim rng As Range
Set rng = Range("myName") 'Selection.Cells
' to do: check the range is a sensible size
RangeToGif rng, "C:\RangeToGif.Gif"
End Sub

You may prefer to copy to a temporary chart sheet which is sized to default
paper size, see arguments for CopyPicture in Help.

Regards,
Peter T

"Barb Reinhardt" wrote in message
...
Hey Jon, I have another related question. How would I save workbook

level
named range "YTD_Summary" as a GIF image?

Thanks again,
Barb

"Jon Peltier" wrote:

If the chartobject's name is in fact "myName.gif", this should work. No

need
to select worksheet or chart object, but you need to export the chart,

not
the parent chartobject.

For Each WS In aWB.Worksheets
For Each ChtObj In WS.ChartObjects

If ChtObj.Name = "myName.gif" Then
fname = aWB.Path & "\myFileName.gif"
ChtObj.Chart.Export Filename:=fname, FilterName:="GIF"
End If
Next ChtObj
Next WS

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Barb Reinhardt" wrote in

message
...
I have the following snippet of code to save a chart as a GIF. What am

I
missing?

For Each WS In aWB.Worksheets
For Each ChtObj In WS.ChartObjects

If ChtObj.Name = "myName.gif" Then
fname = aWB.Path & "\myFileName.gif"
WS.Select
ChtObj.Select
ChtObj.Export Filename:=fname, FilterName:="GIF"
End If
Next ChtObj
Next WS


Thanks,
Barb Reinhardt







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default VBA to save a chart as a GIF

See if this helps
For Each c In ActiveSheet.Shapes
'MsgBox c.Name
if c.Name = "Picture 1" Then MsgBox "OK"
Next

Sub ExportChartGIF()
ActiveChart.Export Filename:="C:\a\MyChart.gif", _
FilterName:="GIF"
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Barb Reinhardt" wrote in message
...
I have the following snippet of code to save a chart as a GIF. What am I
missing?

For Each WS In aWB.Worksheets
For Each ChtObj In WS.ChartObjects

If ChtObj.Name = "myName.gif" Then
fname = aWB.Path & "\myFileName.gif"
WS.Select
ChtObj.Select
ChtObj.Export Filename:=fname, FilterName:="GIF"
End If
Next ChtObj
Next WS


Thanks,
Barb Reinhardt


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save chart as .BMP instead of .GIF? Fan924 Charts and Charting in Excel 1 August 21st 09 08:59 AM
Save chart as 800x600 GIf Fan924 Charts and Charting in Excel 3 August 20th 09 11:31 PM
Save chart (that's on a chart sheet) to html file? JoeFrench Charts and Charting in Excel 0 January 24th 08 12:11 PM
Is it possible to save an excel chart as .emf? Jeff Charts and Charting in Excel 0 March 28th 07 03:02 PM
Save excel chart Stevie D Charts and Charting in Excel 9 March 3rd 05 01:18 PM


All times are GMT +1. The time now is 03:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"