View Full Version : Exporting Drawing Objects from Excel
colsand
06-14-2007, 05:36 AM
I have some VBA code that allows me to export Excel charts as GIF files.  Does anyone know if it is possible to do the same thing with drawing objects?
 
The code I have for exporting charts is:
 
ActiveChart.Export Filename:="c:\chart.gif", FilterName:="GIF"
 
Thank you.
johnske
06-14-2007, 06:26 AM
Not quite the same, you have to copy and paste the picture into a chart and then export it. Here's some old code I have to demonstrate the basic idea...
 
Option Explicit
 
Sub ExportPictureName()
 
     Dim MyChart As String, PictureName As String
     Dim PicWidth As Long, PicHeight As Long
     
     Application.ScreenUpdating = False
     On Error GoTo Finish
     PictureName = Selection.Name
     With Selection
           PicHeight = .ShapeRange.Height
           PicWidth = .ShapeRange.Width
     End With
     
     Charts.Add
     ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
     Selection.Border.LineStyle = 0
     MyChart = Selection.Name & " " & Split(ActiveChart.Name, " ")(2)
     
     With ActiveSheet
           With .Shapes(MyChart)
                 .Width = PicWidth
                 .Height = PicHeight
           End With
           
           .Shapes(PictureName).Copy
           
           With ActiveChart
                 .ChartArea.Select
                 .Paste
           End With
           
           .ChartObjects(1).Chart.Export Filename:="MyPic.jpg", FilterName:="jpg"
           .Shapes(MyChart).Cut
     End With
     
     Application.ScreenUpdating = True
     Exit Sub
     
Finish:
     MsgBox "You must select a picture"
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.