Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Excel Range from PowerPoint

Status
Not open for further replies.

Rebam98

Computer
Mar 28, 2006
14
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
 
Replies continue below

Recommended for you

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.
 
THANK YOU SO MUCH!! I never had to put the . when using Excel so I guess I didn't know ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor