Solved

Pasting an Excel chart into Powerpoint using VBA

Posted on 2001-09-14
2
1,498 Views
Last Modified: 2008-03-10
I know how to paste an Excel chart into Powerpoint using VBA, but is there a way to paste it as a picture?

When I tried to record a macro in Powerpoint using paste special > picture, VBA code is not generated.

Any ideas?

Phil
0
Comment
Question by:phil_hearn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 100 total points
ID: 6483187
Hi Phil, only a workaround here because that's teh nature of the beast

from an answer somewhere else

The macro below simulates a PasteSpecial as Enchanced Meta file routine
The sub routine picks up the chart from excel, creates an instance of word,
pastes the chart as an enchanced meta file into it, then copies the metafile
back to the clipboard, finally pasting the meta file into the current slide
in powerpoint

No error handling has been provided in the example so please incorprorate
it. Hope it helps.

' ==== Beginning of Code ====
Sub OurOwnPasteSpecial()
   Dim wrdDoc As Object
   Dim wrdApp As Object
   Dim xlApp As Object
   Dim xlWrkBook As Object
   Dim lCurrSlide As Long

    Set xlApp = CreateObject("Excel.Application")
         Set xlWrkBook = xlApp.Workbooks.Open("C:\BOOK1.XLS")

    xlWrkBook.Worksheets(1).ChartObjects(1).Copy

    ' As Brian mentioned in an earlier posting, there  is no PasteSpecial
    ' method available in PowerPoint. Hence we have to circumvent
    ' that by either using the PasteSpecial of Excel or Word and then
    ' copying the Picture back into PowerPoint

   ' Get the slide number to paste the meta file later.
    lCurrSlide = ActiveWindow.Selection.SlideRange.SlideNumber
   ' Create a Word Instance.
    Set wrdApp = CreateObject("Word.Application")
    Set wrdDoc = wrdApp.documents.Add()

   ' Pastes the information on the Clipboard into the Word document as
   ' an Enhanced Metafile.
   With wrdApp.ActiveWindow.Selection
        .PasteSpecial DataType:=wdPasteEnhancedMetafile
        .Copy  ' Copy the MetaFile back to the clipboard
   End With

   ' Paste the metafile onto the PowerPoint slide.
   ActivePresentation.Slides(lCurrSlide).Shapes.Paste

   ' Close the document without saving changes.
   wrdDoc.Close (wdDoNotSaveChanges)
   wrdApp.Quit

   ' Close the open workbook without saving changes
    xlWrkBook.Close (False)
    xlApp.Quit

    Set xlApp = Nothing
    Set xlWrkBook = Nothing
    Set wrdApp = Nothing
    Set wrdDoc = Nothing
End Sub
' ==== End of Code ====
--
Regards
Shyam Pillai

you see this is a hell of work around using Word and the clipboard to get something of your liking

HTH:O)Bruintje
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6483528
Manually, you can do it and it works very well. Programmatically, the command is not available to PPT in VBA, which is in the other programs in Office. The development team on PPT VBA seems to just not have had
enough time to implement this in prior versions since they do indicate that there is no reason that it could not be done since it is inherent in the core VBA code model.

from Brian Reilly Powerpoint MVP.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook Free & Paid Tools
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question