Results 1 to 7 of 7

Thread: Export Chart as Graphic

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Mac Moderator VBAX Expert shades's Avatar
    Joined
    May 2004
    Location
    Kansas City, USA
    Posts
    638
    Location
    Quote Originally Posted by cscribner
    in the VBA help file, when you search for "export chart", it offers this example:
    [VBA]Charts(1).Export _
    FileName:="current_sales.gif", FilterName:="GIF" [/VBA]
    But this throws me an error when I try to run it. I may have a clue why: It says that
    Some examples of valid FilterName values are GIF, JPEG, and PNG.
    On the Macintosh, graphics export filters are installed in the
    Microsoft Office X:Shared Applications:Graphic Filters folder.
    But when I look in that folder, I only have two files:
    -EPS Import
    -Metafile Import
    Do you know where I can get more of these Microsoft file converter files? Or am I barking up the wrong tree? Can any of you use this code as-is?
    Howdy. Not sure if this is helpful but this code works well (XL 2004, OS X 10.3.9); but it may not be what you need. It exports as picture to Powerpoint. The first is for a range, the second is for a chart.

    Code from Jon Peltier's site, where you can find additional examples.

    [VBA]
    Sub RangeToPresentation()
    ' Set a VBE reference to Microsoft PowerPoint Object Library for Office

    Dim PPApp As PowerPoint.Application

    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide

    ' Make sure a range is selected
    If Not TypeName(Selection) = "Range" Then
    MsgBox "Please select a worksheet range and try again.", vbExclamation, _
    "No Range Selected"
    Else
    ' Reference existing instance of PowerPoint 2002

    Set PPApp = GetObject(, "Powerpoint.Application")
    ' Reference active presentation
    Set PPPres = PPApp.ActivePresentation
    PPApp.ActiveWindow.ViewType = ppViewSlide
    ' Reference active slide
    Set PPSlide = PPPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)

    ' Copy the range as a piicture
    Selection.CopyPicture Appearance:=xlScreen, _
    Format:=xlPicture

    ' Paste the range
    PPSlide.Shapes.Paste.Select

    ' Align the pasted range
    PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
    PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

    ' Clean up
    Set PPSlide = Nothing
    Set PPPres = Nothing
    Set PPApp = Nothing
    End If

    End Sub

    Sub ChartToPresentation()
    ' Set a VBE reference to Microsoft PowerPoint Object Library

    Dim PPApp As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide

    ' Make sure a chart is selected
    If ActiveChart Is Nothing Then
    MsgBox "Please select a chart and try again.", vbExclamation, _
    "No Chart Selected"
    Else
    ' Reference existing instance of PowerPoint 2002
    Set PPApp = GetObject(, "Powerpoint.Application")
    ' Reference active presentation
    Set PPPres = PPApp.ActivePresentation
    PPApp.ActiveWindow.ViewType = ppViewSlide
    ' Reference active slide
    Set PPSlide = PPPres.Slides _
    (PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)

    ' Copy chart as a picture
    ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, _
    Format:=xlPicture

    ' Paste chart
    PPSlide.Shapes.Paste.Select

    ' Align pasted chart
    PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
    PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

    ' Clean up
    Set PPSlide = Nothing
    Set PPPres = Nothing
    Set PPApp = Nothing
    End If

    End Sub
    [/VBA]
    Last edited by shades; 05-06-2006 at 06:22 PM. Reason: Adding link

    Software: LibreOffice 3.3 on Mac OS X 10.6.5
    (retired Excel 2003 user, 3.28.2008 )
    Humanware: Older than dirt
    --------------------
    old, slow, and confused
    but at least I'm inconsistent!

    Rich

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •