Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Looking at Excel from Word, can't select range

Status
Not open for further replies.

McGinley57

Technical User
Feb 12, 2008
16
US
I want to use Word VBA to select a range within an open spreadsheet. The simple code below points up the problem I'm having. Once the code hits the Range statement, I get a 1004 error. Everything else works fine. I believe my references are in order: Word VBA references XL5EN32.olb. Can anyone tell me what I'm doing wrong? Much appreciated.


Sub SelectWSRange()
Dim msg As String
Dim wb As Excel.Workbook
Dim xapp As Excel.Application

Set xapp = GetObject(, "Excel.Application")
Set wb = xapp.Workbooks(1)
msg = wb.Name
With wb.Worksheets(1)
Range("a1").Select
End With
MsgBox msg, , "Open Workbooks"

End Sub

MsgBox msg, , "Open Workbooks"

End Sub
 
The problem is that range is also defined for documents, at least I think that's the problem. How about using Excel-specific notation: [a1].select?

_________________
Bob Rashkin
 
Shucks, ck1999. That did it, and I'm a little embarrassed--a missing dot. Thanks to both of you for the responses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top