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?
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?