×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Accessing Excel Range from PowerPoint

Accessing Excel Range from PowerPoint

Accessing Excel Range from PowerPoint

(OP)
Hi-

I'm working on something and cannot for the life of me figure out why it won't work.

I need to pull in a range of cells from Excel into powerpoint, to complete a presentation. This is the code I have. It's not complete because I have been stepping through the code until I get to the end, and it give me the generic '1004' application or object defined error.

The problem comes in selecting a range in Excel. I can get cell "A1," i.e. a single cell, just fine but when I try to define a larger range, it crashes. I've racked my brain for every possible thing I could do. I tried setting up a named range and referencing it (in the commented out code below) to no avail.

The code below is a little simpler than what I am doing, to isolate out the main problem. Basiclaly I just need to be able to pick out a range of cells in Excel from PowerPoint.

Please help.  

sub get_excel_range()


Dim amberwrkbook As Excel.Workbook



Set amberwrkbook = GetObject("H:\Notes\Learning VBA\Making Summary to play with.xls")

amberwrkbook.Application.Sheets(24).Range("A1").Select '<-- works just fine



amberwrkbook.Application.Sheets(24).Range(Cells(1, 1), Cells(8, 8)).Copy '<-- CRASH, FAIL BURN!

'amberwrkbook.Application.Names.Add "Summary_Sheet", Range(Cells(1, 1), Cells(8, 8))


'amberwrkbook.Application.Sheets(24).Range("Summary_Sheet").Copy

......

End Sub

RE: Accessing Excel Range from PowerPoint

The catch is that you have properly referenced the context of the Range, but not the context of the Cells objects. So that is what fails, because VBA will try to find it in the Global context. This works in Excel VBA, since the active workbook is always in that context. What you need to do is the following:

CODE

Sub GetExcel()

Dim amberwrkbook As Excel.Workbook

    Set amberwrkbook = GetObject("H:\Notes\Learning VBA\Making Summary to play with.xls")
    With amberwrkbook.Sheets(24)
        .Range(.Cells(1, 1), .Cells(8, 8)).Copy
    End With
End Sub
don't forget to put the . (dot) in front of each Cells statement.

Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.

RE: Accessing Excel Range from PowerPoint

(OP)
THANK YOU SO MUCH!!  I never had to put the . when using Excel so I guess I didn't know ...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources