Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using GetObject() to retrieve open workbook
Message
From
11/06/2004 13:55:22
Jason Lanier
Ofs Brightwave Carrollton
Carrollton, Georgia, United States
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Using GetObject() to retrieve open workbook
Miscellaneous
Thread ID:
00912825
Message ID:
00912825
Views:
72
I am having a problem assigning an open Pivot Table in Excel to an object. The following code works fine if opening it:

oExcel = CreateObject("EXCEL.APPLICATION")
oExcel.Application.Visible = .T.
oExcel.Workbooks.Open("PivotTableExample.xls")
oExcel.Sheets("Sheet1").Select

The problem is if Excel is already running with the sheet as the active workbook. I've tried:

oExcel = GetObject(,"EXCEL.APPLICATION")
oWorkBook = oExcel.ActiveWorkbook
and referencing by
oExcel.Sheets("Sheet1").Select

or

oExcel = GetObject("PivotTableExample.XLS","EXCEL.SHEET")
(This works, but I still cannot find the reference to the sheet.)

but neither work. How can I assign the object to an open workbook/sheet without having to start with having to close and then re-start Excel?

Thanks,
Jason
Next
Reply
Map
View

Click here to load this message in the networking platform