I have a peice of code which copies a range from my excel file and pastes it onto my activeslide in PowerPoint. After hours of attempts to get the range from excel pasted as a table (NOT an image), I found the below code to work successfully. Note: myPP = powerpoint application.
myPP.CommandBars.ExecuteMso "PasteExcelTableSourceFormatting"
myPP.CommandBars.ReleaseFocus
The problem is that when I execute the macro, the table is pasted, but vba does not recognize the table unless the code is stepped through. I've tested this with the below code. During execution the code is skipped entirely, but during step-through it triggers.
For Each shp In activeSlide.Shapes
If shp.HasTable Then
MsgBox shp.Name
End If
Next
Below is the full code. Basically I just want the excel range to be pasted into my powerpoint as a table, and for that table to be expanded to fit the slide. I'm open to suggestions in revising it a bit. Thanks for your help
Dim myPP as Object
Dim activeSlide as Object
Dim shp as Object
Worksheets("Sheet2").Activate
Worksheets("Sheet2").Range(Cells(1,1), Cells(4,7)).Copy
Worksheets("Sheet1").Activate
myPP.CommandBars.ExecuteMso "PasteExcelTableSourceFormatting"
myPP.CommandBars.ReleaseFocus
Dim myTable As String
For Each shp In activeSlide.Shapes
If shp.HasTable Then
MsgBox shp.Name
myTable = shp.Name
End If
Next
With activeSlide.Shapes(myTable)
.Left = 23
.Top = 105
.Width = 650
.Height = 375
End With
For ASH
Dim myPP As Object 'Powerpoint.Application
Dim myPres As Object 'Powerpoint.Presentation
Dim activeSlide As Object 'Powerpoint.Slide
Set myPP = CreateObject("Powerpoint.Application")
myPP.Visible = True
Set myPres = myPP.Presentations.Add
myPP.ActiveWindow.ViewType = 1 'ppViewSlide
Set activeSlide = myPres.slides.Add(1, 12) 'ppLayoutBlank
DoEvents
before the loop? And to add some waiting time for the operation to finish? - A.S.HmyPP
andactiveSlide
? - A.S.H