General information
Category:
COM/DCOM and OLE Automation
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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only