Hi everyone!
I am using Excel VBA to copy and paste data to a PowerPoint presentation. The data copies titles, text and tables from Excel into PowerPoint. Ever since I have added more steps to it, for some reason it skips multiple steps. It does select the tables, but for some reason it does not update them. When I go through the code step by step with F8 it does work for some reason. Please help out!
You can find the code here:
Sub Excel_PowerPoint_deck()
Dim sh As Worksheet
Dim saveAs As String
Dim savePath As String
Dim I As Integer
Dim PowerPointApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim PowerPointTable As PowerPoint.Shape
Dim DestinationPPT As String
Set sh = ActiveWorkbook.Sheets("Sheet1") '--------> aanpassen!
Application.ScreenUpdating = False
sh.Activate
' On Error Resume Next
'If PowerPoint is not already open then open PowerPoint
Set PowerPointApp = GetObject(, "Powerpoint.Application")
If PowerPointApp Is Nothing Then
Set PowerPointApp = CreateObject("PowerPoint.Application")
PowerPointApp.Visible = True
End If
DestinationPPT = Range("E30").Value
PowerPointApp.Presentations.Open (DestinationPPT)
PowerPointApp.ActivePresentation.Slides(3).Select
'-------------------------- TITEL -----------------------------------------
'Pastes the information in the PowerPoint template
PowerPointApp.ActivePresentation.Slides(3).Shapes(2).TextFrame.TextRange.Text = sh.Range("E5").Value
' find on Slide Number 1 which object ID is of Table type (you can change to whatever slide number you have your table)
With PowerPointApp.ActivePresentation.Slides(3).Shapes
For I = 1 To .Count
If .Item(I).HasTable Then
ShapeNum = I
End If
Next
End With
'-------------------------- Tabel 1 -----------------------------------------
Set PowerPointTable = PowerPointApp.ActivePresentation.Slides(3).Shapes(ShapeNum - 2)
' copy range from Excel sheet
Range("E9:G11").Copy
' select the Table cell you want to copy to >> modify according to the cell you want to use as the first Cell
PowerPointTable.Table.Cell(1, 1).Shape.Select
' paste into existing PowerPoint table - use this line if you want to use the PowerPoint table format
PowerPointApp.CommandBars.ExecuteMso ("PasteExcelTableDestinationTableStyle")
'PowerPointApp.CommandBars.ExecuteMso ("PasteExcelChartSourceFormatting")
Application.CutCopyMode = False
Application.Wait (Now() + TimeValue("0:00:04"))
'-------------------------- Tabel 2 -----------------------------------------
Set PowerPointTable = PowerPointApp.ActivePresentation.Slides(3).Shapes(ShapeNum - 1)
' copy range from Excel sheet
Range("M9:O11").Copy
' select the Table cell you want to copy to >> modify according to the cell you want to use as the first Cell
PowerPointTable.Table.Cell(1, 1).Shape.Select
' paste into existing PowerPoint table - use this line if you want to use the PowerPoint table format
PowerPointApp.CommandBars.ExecuteMso ("PasteExcelTableDestinationTableStyle")
'PowerPointApp.CommandBars.ExecuteMso ("PasteExcelChartSourceFormatting")
Application.CutCopyMode = False
Application.Wait (Now() + TimeValue("0:00:06"))
'-------------------------- Tabel 3 -----------------------------------------
Set PowerPointTable = PowerPointApp.ActivePresentation.Slides(3).Shapes(ShapeNum)
' copy range from Excel sheet
Range("T9:V11").Copy
' select the Table cell you want to copy to >> modify according to the cell you want to use as the first Cell
PowerPointTable.Table.Cell(1, 1).Shape.Select
' paste into existing PowerPoint table - use this line if you want to use the PowerPoint table format
PowerPointApp.CommandBars.ExecuteMso ("PasteExcelTableDestinationTableStyle")
'PowerPointApp.CommandBars.ExecuteMso ("PasteExcelChartSourceFormatting")
Application.CutCopyMode = False
Filename = sh.Range("E31").Value
ChDir (ThisWorkbook.Path)
PowerPointApp.ActivePresentation.saveAs Filename
PowerPointApp.ActivePresentation.Close
End Sub
For some reason I cannot upload the PowerPoint, but it is a very simple PPT template with a title and 3 tables.
Thank you for your help!
Bookmarks