How Do I Assign a Workbook to an Object Variable?

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

Using Access 2003 VBA, how do I open a Excel Workbook and then assign it
to an Excel.Workbook object variable so it is easily referenced?

TIA,
Dan
 
Try:

On Error Resume Next
Set objXL = GetObject(, "Excel.Application")
Err.Clear
If objXL Is Nothing Then
Set objXL = CreateObject("Excel.Application")
End If
Set Mybook = objXL.Workbooks.Add

And then you can access the workbook using:
Mybook.Sheets("Sheet1").Select
And then access that sheet as follows:
objXL.Rows("1").Select
objXL.Selection.Font.Bold = True

Dave
 
I actually want to open an existing workbook, say c:\test\mybook.xls,
and assign it to object variable to manipulate. I can't seem to get the
syntax correct...
 
Back
Top