Active Member
Power Query
Power Pivot
Power BI
February 23, 2017
Hi guy,
I have this small vba code to copy a picture from an excel file into powerpoint. it seems to work with excel 2010 but not with excel 2013.
can somebody help understand why.
Dim Ppres As PowerPoint.Presentation
Dim Papp As PowerPoint.Application
Papp.Visible = msoTrue
Set Pslide = Ppres.Slides.Add(1, ppLayoutBlank)
Sheet1.Range("A1:I17").CopyPicture Appearance:=xlScreen, Format:=xlPicture
'Dim Pshape As PowerPoint.Shape
'(the line above has to be comment out in order to avoid run time error after setup)
Set Pshape = Pslide.Shapes.Paste
Pshape.Left = 100
Pshape.Top = 50
Pshape.ScaleHeight 1.2, msoTrue
Active Member
Power Query
Power Pivot
Power BI
February 23, 2017
October 5, 2010
Hi Babacar,
I'm using Excel 2013 and it works.
Have you tried stepping through the code using F8 to see where the code breaks?
Please attach your workbook and I will see what I can find.
Also, please specify exactly what is not working.
- What line of code does the debugger highlight?
- What error message are you receiving?
Regards
Phil
Active Member
Power Query
Power Pivot
Power BI
February 23, 2017
Hi Phil,
the error message is [run time error 424 - object required].
the line code where it stop is : Pshape.Left = 100
below are the codes:
Dim Ppres As PowerPoint.Presentation
Dim Papp As PowerPoint.Application
Papp.Visible = msoTrue
Set Pslide = Ppres.Slides.Add(1, ppLayoutBlank)
Sheet1.Range("A1:I17").CopyPicture Appearance:=xlScreen, Format:=xlPicture
Dim Pshape As Object
'(the line above has to be comment out in order to avoid run time error after setup)
' Set Pshape = Pslide.Shapes.Paste
Set Pshape = Pslide.Shapes.PasteSpecial(DataType:=2)
Pshape.Left = 100
Pshape.Top = 50
Pshape.ScaleHeight 1.2, msoTrue
[Image Can Not Be Found]
October 5, 2010
Hi Babacar,
The code above and the workbook you emailed me both work on my Excel 2013.
If your code is stopping at Pshape.Left = 100 with the error [run time error 424 - object required] that indicates that Pshape is not defined. But if you pasted the picture into PP then Pshape should be defined.
Does the picture appear in PP?
The only way I can recreate this error is to comment out the DIM and SET statements for Pshape i.e.:
Sub OpenPowerPoint() Dim Pslide As PowerPoint.Slide Dim Ppres As PowerPoint.Presentation Dim Papp As PowerPoint.Application Set Papp = New PowerPoint.Application Papp.Visible = msoTrue Set Ppres = Papp.Presentations.Add Set Pslide = Ppres.Slides.Add(1, ppLayoutBlank) 'Range("A1:I17") Sheet1.Range("A1:I17").CopyPicture Appearance:=xlScreen, Format:=xlPicture 'Dim Pshape As Object '(the line above has to be comment out in order to avoid run time error after setup) ' Set Pshape = Pslide.Shapes.Paste 'Set Pshape = Pslide.Shapes.PasteSpecial(DataType:=2) Pshape.Left = 100 Pshape.Top = 50 Pshape.ScaleHeight 1.2, msoTrue End Sub
Can you please add this to the top of all your code modules too, it checks for undefined variables
Option Explicit
1 Guest(s)