McGinley57
Technical User
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
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