Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using GetObject() to retrieve open workbook
Message
From
14/06/2004 07:09:27
Jason Lanier
Ofs Brightwave Carrollton
Carrollton, Georgia, United States
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00912825
Message ID:
00913366
Views:
14
Through some trial and error I finally found it. The example that I had been using was in VB, but it's slightly different in VFP.
Here's what worked.

objExcel = GETOBJECT(,"Excel.Application")
objWorkbook = objExcel.ActiveWorkbook
objSheet = objWorkbook.ActiveSheet

This was the only way I could find to reference a sheet that is already running.

Thanks,
Jason

>Sorry, not quite clear what do you mean, "still cannot find a reference to the sheet". Do you get any errors?
>
>Probably there is no active sheet, or you need to activate the workbook, or there is no sheet with the name "Sheet1".
>
>
>>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
Previous
Reply
Map
View

Click here to load this message in the networking platform