views:

84

answers:

1

I cant find any way to do this. What I have now is that it copy the range as an image:

Dim XLApp As Excel.Application 
Dim PPSlide As Slide 

Set XLApp = GetObject(, "Excel.Application") 
XLApp.Range("A1:B17").Select 
XLApp.Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
PPSlide.Shapes.Paste.Select

this works like a charm, but is it possible to get it to copy the range as a table instead of picture?

+2  A: 

Well, if I was copying it manually, I would probably do a Paste Special and choose "Formatted Text (RTF)" as the type. I'm sure you can mimic that in VBA.

Edit

Aah, here we go. Do this in your powerpoint:

  1. Go to Insert->Object
  2. Choose your Excel file. Check the Link option.

A link to your XL file is now embedded in your PP file. When the data in your XL file changes, you can:

  1. Update it manually by Right-Click->Update Link.
  2. Update it automatically by VBA by using something like ActivePresentation.UpdateLinks

This is a very different approach than what you were doing first, but I believe it gets you closer to your goal. It has it own problems, though, but those can be worked out.

PowerUser
I've tried PPSlide.Selection.PasteExcelTable - but this doesnt work. and also PPSlide.Shapes.PasteExcelTable . Any ideas?EDIT: I cant record macros in powerpoint, but when I try to do it in word and copy the table from excel the way u suggest I get this code: Selection.PasteAndFormat (wdTableOriginalFormatting) - is there something similar i can use in the powerpoint vba code?
iper
Hmm, why can't you use the PasteExcelTable methods? What error do you get?
PowerUser
Compile error: Method or data member not foundIs the error i get when I try PPSlide.Selection.PasteExcelTable or PPSlide.Shapes.PasteExcelTable. So i guess the syntax isnt all good then?
iper
(A little training tip: VBA has a feature called Intellisense which gives you a list of available methods/properties/etc. In VBA, if you type "PPSlide." you should see a drop-down list of the members of that class. If you don't see what you're looking for, then you're doing it wrong. Very helpful when you're designing something you've never done before)
PowerUser
See my Edit above. An alternative approach.
PowerUser
Thanks for the alternative solution. But I can't get it to work. This is mainly because my excel document I try to link to is empty and have a macro to run on the on open event that creates the content dynamically from an external xml source, and the document is never saved. I wish there would be an easier approach to this problem, but it seems like I may have to try to tweak my macros to get it work this way, if no one else have any other solutions. Thanks for the help, really appreciate it!
iper
Let me get this straight: You have an xml source document that feeds data to an Excel file that feeds data to a powerpoint? What if you just simulate the powerpoint in Excel? 1 less format to worry about.
PowerUser