Solved

Using VBA to copy Excel range to PowerPoint table

Posted on 2014-01-02
3
4,937 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

PowerPoint is the go-to presentation software for millions of users around the world. Many presentations use basic text features but you can really make special text jump out of your slide by applying this bubble text design process. This article ha…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
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…

837 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