Copy embedded tables from Excel to PowerPoint with VBA

_Gregor

New Member
Joined
Jul 30, 2015
Messages
1
Hey all,

On one of the projects I have an excel file and a macro to automaticaly generate 20 PowerPoints with tables imbeded so that they can be updated when the excel numbers change.
To do this I call the following Sub:

Code:
Sub pp_Paste(wb As String, ws As String, Ran As String, nSlide As Integer, pp As Variant, posWidth As Integer, posTop As Integer, posLeft As Integer)
   Dim Object1 As Variant
   Set Object1 = Workbooks(wb).Worksheets(ws).Range(Ran)
   Object1.Copy
   pp.Slides(nSlide).Select
   
   With pp.Slides(nSlide).Shapes.PasteSpecial(DataType:=ppPasteOLEObject, _
               Link:=msoTrue)
       .Left = posLeft
       .Width = posWidth
       .Top = posTop
   End With
   
   'clean
   Object1 = Empty
   Application.CutCopyMode = False
End Sub

The problem is that it offten crashes with an error "Shapes.PasteSpecial: Invalid request. Specified data type is unavalible". If after that I go to the debug mode, and run the code again, the macro runs perfectly. My hypothesis is that that excel tries to paste before the copy comand was finished, but I am not sure.

So my question is either if there is a way to implement this differently or if it can be fixed.

Thanks for your help :)
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi and welcome to the Board

This is working for me:

Code:
Sub pp_Paste(wb$, ws$, Ran$, nSlide%, pp, posWidth%, posTop%, posLeft%)
Dim Object1, s
Set Object1 = Workbooks(wb).Worksheets(ws).Range(Ran)
Object1.Copy
Application.Wait TimeValue("0:00:02") + Now()
pp.Slides(nSlide).Select
DoEvents
pp.Slides(nSlide).Shapes.PasteSpecial DataType:=ppPasteOLEObject, Link:=msoTrue
Set s = pp.Slides(nSlide).Shapes(pp.Slides(nSlide).Shapes.Count)
s.Left = posLeft
s.Width = posWidth
s.Top = posTop
Object1 = Empty
Application.CutCopyMode = False
End Sub


Sub Main()
Dim pp As PowerPoint.Presentation, papp As PowerPoint.Application
Set papp = GetObject(, "PowerPoint.Application")
Set pp = papp.ActivePresentation
pp_Paste "Automation", "Master", "b2:h9", 2, pp, 200, 90, 40
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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