View Single Post
 
Old 10-09-2012, 08:40 PM
omahadivision omahadivision is offline Windows 7 32bit Office 2007
Novice
 
Join Date: Oct 2012
Posts: 28
omahadivision is on a distinguished road
Default 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
That code works fine, so I thought I'd do

Code:
       Dim objChart As ChartObject
       
    On Error Resume Next
    Set objChart = ActiveSheet.ChartObjects(1).Select
    
    Selection.Export Filename:="C:\test.jpg", FilterName:="jpg"
Nothing ever shows up in C:\ or any other folder I've tried. I also wondered if I needed to set objChart as something else so that it as already selected, based on something I saw online:

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"
Still doesn't work. No error messages but no file either. I only have one chart in my Excel file. Can you see anything I might have done wrong?

-Dave
Reply With Quote