Dim oExcel As Excel.Application
Dim oWrkBook As Excel.Workbook
Dim oWrkSheet As Excel.Worksheet
Dim oOrdDetail As Excel.Range
Dim oFirstCell As Excel.Range
Dim oLastCell As Excel.Range
Dim sPath As String
Set oExcel = CreateObject("Excel.application")
oExcel.Visible = True
sPath = "C:\Test_Output.xls"
Set oWrkBook = oExcel.Workbooks.Open(sPath)
Set oWrkSheet = oWrkBook.Sheets(1)
Set oFirstCell = oWrkSheet.Range("A1")
' Note you used xlLastCell on ActiveCell:
Set oLastCell = oWrkSheet.Cells.SpecialCells(xlCellTypeLastCell)
Set oOrdDetail = oWrkSheet.Range(oFirstCell, oLastCell)
Debug.Print oOrdDetail.Address
Set oLastCell = Nothing
Set oFirstCell = Nothing
Set oOrdDetail = Nothing
Set oWrkSheet = Nothing
Set oWrkBook = Nothing
oExcel.DisplayAlerts = False
oExcel.Quit
Set oExcel = Nothing
End Sub
"Cooper, Scott A." <Cooper...@discussions.microsoft.com> wrote in message
news:F57FC4F6-13A3-41CF...@microsoft.com...
>I am creating a Word macro to import an Excel range into a document but I
>get
> an error number 462 - "The remote server machin does not exist or is not
> availaible." which occurs every other time the macro runs. Also I can not
> get
> Excel to unload from memory after the task. What's up with this?
>
> Sub Macro2()
> Dim oExcel As Excel.Application
>
> Set oExcel = CreateObject("Excel.application")
> oExcel.Visible = True
>
> sPath = "C:\Test_Output.xls"
> Set oWrkBook = oExcel.Workbooks.Open(sPath)
> Set oWrkSheet = oWrkBook.Sheets(1)
>
> Set oOrdDetail = oExcel.Range("A1",
> ActiveCell.SpecialCells(xlLastCell))
>
> Debug.Print oOrdDetail.Address
>
> oExcel.Visible = False
> Set oWrkSheet = Nothing
> Set oWrkBook = Nothing
> Set oExcel = Nothing
>
> End Sub
>
> --
> Scott A. Cooper