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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to control Excel from Word

Status
Not open for further replies.

josedeman

Programmer
Jan 20, 2004
23
NL
This code works fine in Excel when I put it in a macro. When I put the same code in a Word macro I get an error while executing.
Excel:
Sub testnummer()
Range("A2").Select
Selection.End(xlDown).Select
End Sub

Word (the code crashes at the last line):
Private Sub cmdOpslaan_Click()
Dim oExcel As Excel.Application
Dim excWorkbook As Excel.Workbook

Set oExcel = CreateObject("Excel.Application")
Set excWorkbook = oExcel.Workbooks.Open("c:\mysheet.xls")
oExcel.Visible = True

excWorkbook.Worksheets(1).Range("A2").Select
Selection.End(xlDown).Select
End Sub

Does anybody hav any idea why this doesn't work?
 
Replace this:
Selection.End(xlDown).Select
By this:
oExcel.Selection.End(xlDown).Select

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
need to qualify "SELECTION" to that in the workbook rather than in the Wrod doc.

excWorkbook.Worksheets(1).Range("A2").Select
excWorkbook.Selection.End(xlDown).Select


Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top