Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Excel and Word automation

50 views
Skip to first unread message

Geoff

unread,
Dec 6, 2006, 5:31:49 AM12/6/06
to
Sub GetExcelData()

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


0 new messages