#1
|
|||
|
|||
Making VBA select chart and then export as picture
Hello All,
So I have what seems to be an insanely easy coding question, but it's driving me crazy. So I have this code that selects a chart and then copies it, and I wanted to make it save the chart as a picture instead of copying it. Here is the copying code: Code:
Dim objChart As ChartObject On Error Resume Next Set objChart = ActiveSheet.ChartObjects(1).Select Selection.CopyPicture _ Appearance:=xlScreen, Format:=xlBitmap Code:
Dim objChart As ChartObject On Error Resume Next Set objChart = ActiveSheet.ChartObjects(1).Select Selection.Export Filename:="C:\test.jpg", FilterName:="jpg" Code:
Dim objChart As ChartObject Dim slcChart As ChartObject On Error Resume Next Set objChart = ActiveSheet.ChartObjects(1).Select Set slcChart = ActiveSheet.ChartObjects(1) If ActiveChart Is Nothing Then MsgBox "No charts have been detected on this sheet", 0 End If slcChart.Export Filename:="C:\test.jpg", FilterName:="jpg" -Dave |
#2
|
||||
|
||||
So it's the chart class, not the chartobject class which has an export method. This worked fine for me (I set up a chart before running the code):
Code:
Sub foo() Dim cto As ChartObject Dim cht As Chart 'get a reference to the chartobject on the sheet Set cto = Sheet1.ChartObjects(1) 'get a reference to the chart Set cht = cto.Chart 'export the chart as a jpg cht.Export "C:\Temp\MyChartPic.jpg", "JPG" End Sub |
#3
|
|||
|
|||
Thanks! It works now! Sorry about the delay; I honestly lost the link
-Dave |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA code to group picture to export as one | RenaatS | PowerPoint | 3 | 03-05-2012 12:40 PM |
Export resource custom field to excel chart | jtorres | Project | 0 | 03-15-2011 05:16 AM |
Can't select or edit chart data | itguy | PowerPoint | 2 | 09-19-2010 10:13 AM |
Making a bar chart with several data entries | Blondie1966 | PowerPoint | 2 | 04-28-2010 03:00 PM |
How To Export A Picture From Word? | abrogard | Drawing and Graphics | 0 | 08-10-2009 06:27 PM |