• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 65
  • Last Modified:

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
0
LUIS FREUND
Asked:
LUIS FREUND
  • 3
  • 2
  • 2
2 Solutions
 
NorieVBA ExpertCommented:
Have you checked there is a sheet with the exact name 'PENDING_REV_REPORT' in the active workbook?
0
 
LUIS FREUNDAuthor Commented:
Yes....
0
 
Wayne Taylor (webtubbs)Commented:
Try specifying the workbook as well...

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

Open in new window

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
NorieVBA ExpertCommented:
The only reason for the described error is that there is no worksheet with that exact name in the currently active workbook.

Adding a workbook reference, as Wayne suggests, might work.
0
 
Wayne Taylor (webtubbs)Commented:
You'll get a "Subscript out of range" error if it can't find the worksheet. Typically the above error occurs when not fully referencing the correct objects, in this case probably the workbook, or maybe even the Excel application.

Is this code being run from the workbook containing worksheet "PENDING_REV_REPORT"?
0
 
NorieVBA ExpertCommented:
Wayne

Oops, you are right - for some reason I thought the code was being run from outside Excel and the error was something 'generic'.
0
 
LUIS FREUNDAuthor Commented:
Thanks Guys....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now