VBA code to replace contents in a Powerpoint table using Excel data

MitchelK

New Member
Joined
Aug 26, 2014
Messages
3
I would like to copy Excel data into an existing Powerpoint table using VBA in order to keep the Powerpoint table formatting, e.g. I need a VBA code to open an existing PPT presentation, select a predefined slide let's say Slide(1), select the Table1 shape in Powerpoint and copy the Excel table data as text into the Powerpoint table, overwriting the existing data. The Excel table is set-up exactly the same as the one in Powerpoint. Using linked/embedded table objects in Powerpoint is not an option.

Below my current VBA Code which pastes the Excel table into a new PPT slide as an HTML object.

Any suggestions?

Many thanks in advance!


Option Explicit

Dim PP As Object
Dim PP_File As Object
Dim PP_Slide As Object
Dim x As Single
Dim ActFileName As Variant


Sub ExporttoPPT()

ActFileName = Sheet1.Range("Source").Value
Set PP = CreateObject("Powerpoint.Application")
PP.Activate
Set PP_File = PP.Presentations.Open(ActFileName)
PP.Visible = True

Copytonewsheet "Rangename", "Title"

Set PP_Slide = Nothing
Set PP_File = Nothing
Set PP = Nothing
Worksheets(1).Activate


Exit Sub


End Sub

Private Sub Copytonewsheet(myRangeName As String, MyTitle As String)

Application.GoTo Reference:=myRangeName
Selection.Copy

PP.ActiveWindow.ViewType = 1
PP.ActiveWindow.View.GotoSlide Index:=PP.ActivePresentation.Slides.Add(Index:=PP.ActivePresentation.Slides.Count + 1, Layout:=16).SlideIndex
PP.ActiveWindow.View.PasteSpecial 8
PP.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, msoTrue
PP.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, msoTrue

End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi Koen,

Thanks for your reply. As I need to copy & paste about 40 tables from Excel to Powerpoint, I used the code below to solve the issue eventually.

Best, Mitchel


Sub ExporttoPPT()


Application.ScreenUpdating = False
Application.EnableEvents = False
Dim NextShape As Integer
Dim ActFileName As Variant
On Error Resume Next

ActFileName = Sheet1.Range("Source").Value
Set PP = CreateObject("Powerpoint.Application")
PP.Activate
Set PP_File = PP.Presentations.Open(ActFileName)
PP.Visible = True

Range("ExcelTable1").Copy
PP_File.Slides(1).Shapes("Table1").Table.cell(1, 1).Select
PP.ActiveWindow.View.Paste

PP.ActiveWindow.View.GotoSlide (1)

Set PP_Slide = Nothing
Set PP_File = Nothing
Set PP = Nothing
Worksheets(1).Activate

Application.ScreenUpdating = True

Application.EnableEvents = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,018
Messages
6,122,703
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top