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_RE PORT").Ran ge("A1:F28 ").CopyPic ture _
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_RE PORT").Ran ge("A1:F28 ").CopyPic ture _
Appearance:=xlScreen, Format:=xlPicture
PPSlide.Shapes.Paste.Selec t
'PPPres.Slides(PPPres.Slid es.Count). Shapes.Pas te
PP.ActiveWindow.Selection. ShapeRange .Align msoAlignCenters, True
PP.ActiveWindow.Selection. ShapeRange .Align msoAlignMiddles, True
SlideTitle = "My First PowerPoint Slide"
PPSlide.Shapes.Title.TextF rame.TextR ange.Text = SlideTitle
PP.Activate
Set PPSlide = Nothing
Set PPPres = Nothing
Set PP = Nothing
End Sub
Worksheets("PENDING_REV_RE
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_RE
Appearance:=xlScreen, Format:=xlPicture
PPSlide.Shapes.Paste.Selec
'PPPres.Slides(PPPres.Slid
PP.ActiveWindow.Selection.
PP.ActiveWindow.Selection.
SlideTitle = "My First PowerPoint Slide"
PPSlide.Shapes.Title.TextF
PP.Activate
Set PPSlide = Nothing
Set PPPres = Nothing
Set PP = Nothing
End Sub
Have you checked there is a sheet with the exact name 'PENDING_REV_REPORT' in the active workbook?
ASKER
Yes....
Try specifying the workbook as well...
ThisWorkbook.Worksheets("PENDING_REV_REPORT").Range("A1:F28").CopyPicture _
Appearance:=xlScreen, Format:=xlPicture
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Wayne
Oops, you are right - for some reason I thought the code was being run from outside Excel and the error was something 'generic'.
Oops, you are right - for some reason I thought the code was being run from outside Excel and the error was something 'generic'.
ASKER
Thanks Guys....