Solved

Using VBA to copy Excel range to PowerPoint table

Posted on 2014-01-02
3
4,996 Views
Last Modified: 2014-01-03
Hi Experts:

I've done lots of automation between Excel and PowerPoint, including copying Chart objects and copying Excel data into the data table behind a PowerPoint Chart.  

But I can't figure this one out.  Using VBA I want to copy a formatted Excel range into a PowerPoint TABLE.  I want to duplicate what I get when I manually copy the range, then manually paste into PPT, selecting the Keep Source Formatting option.  It's a heat map, so very important to preserve formatting.

Once it's in PowerPoint, I need to be able to further manipulate the table, changing font sizes, adding rows, etc. all of which I know how to do.  Where I'm stuck is getting it to come in as a table.

The following two options both copy the formatting of the source cells, but in one case it's just a picture and in another it's an OLE object I can't manipulate

PPSlide.Shapes.PasteSpecial DataType:=ppPasteEnhancedMetafile
PPSlide.Shapes.PasteSpecial DataType:=ppPasteOLEObject

Open in new window

In the past I've iterated through the range and copied the values into the cells of the PowerPoint table one at a time, but there has to be a better way.

Thanks for your suggestions.
0
Comment
Question by:versatilebb
3 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39753168
Hi,

pls try

ActivePresentation.Application.CommandBars.ExecuteMso ("PasteSourceFormatting")

Open in new window

Regards
0
 
LVL 23

Expert Comment

by:JSRWilson
ID: 39753227
As Rgonzo says "PasteSourceFormatting" models pressing the Keep SAource Format button. It only runs from version 2010.

You will probably need to select the start cell of the table first.

Assuming otbl is a reference to the table and the start cell is 2,2

otbl.Cell(2, 2).Select
CommandBars.ExecuteMso ("PasteSourceFormatting")
0
 

Author Closing Comment

by:versatilebb
ID: 39754528
I knew there was an easier way.  Thanks!

JSR, I didn't use your suggestion of selecting the table cell.  That does not appear to be necessary.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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