Link to home
Start Free TrialLog in
Avatar of LUIS FREUND
LUIS FREUND

asked on

method 'worksheets' of object '_global' failed on my code. from Excel to Power Point

I'm getting an error "method 'worksheets' of object '_global' failed on my code." and the following is highlighted in yellow:
Worksheets("PENDING_REV_REPORT").Range("A1:F28").CopyPicture _
Appearance:=xlScreen, Format:=xlPicture

What I'm trying to do is get an excel sheet range to a powerpoint slide.  Below is the code I'm using.

Sub CopyRangeToPresentation()

Dim PP As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim SlideTitle As String

Set PP = New PowerPoint.Application
Set PPPres = PP.Presentations.Add
PP.Visible = True

Set PPSlide = PPPres.Slides.Add(1, ppLayoutTitleOnly)
PPSlide.Select

Worksheets("PENDING_REV_REPORT").Range("A1:F28").CopyPicture _
Appearance:=xlScreen, Format:=xlPicture

PPSlide.Shapes.Paste.Select
'PPPres.Slides(PPPres.Slides.Count).Shapes.Paste
PP.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
PP.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

SlideTitle = "My First PowerPoint Slide"
PPSlide.Shapes.Title.TextFrame.TextRange.Text = SlideTitle

PP.Activate
Set PPSlide = Nothing
Set PPPres = Nothing
Set PP = Nothing

End Sub
Avatar of Norie
Norie

Have you checked there is a sheet with the exact name 'PENDING_REV_REPORT' in the active workbook?
Avatar of LUIS FREUND

ASKER

Yes....
Try specifying the workbook as well...

ThisWorkbook.Worksheets("PENDING_REV_REPORT").Range("A1:F28").CopyPicture _
 Appearance:=xlScreen, Format:=xlPicture

Open in new window

SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wayne

Oops, you are right - for some reason I thought the code was being run from outside Excel and the error was something 'generic'.
Thanks Guys....