General information
Category:
COM/DCOM and OLE Automation
Title:
Creating spreadsheets
Using OLE automation, I am using VFP7 (SP1) to create and populate a spreadsheet in Excel 2002.
1. Once the sheet is created I sometimes wish to look at it by double-clicking on the .xls file in Windows explorer. With the VFP session still open (eg. waiting at the command line), Excel starts-up, but then 'freezes' before the sheet is displayed. However, if I quit VFP completely and then double-click on the file, Excel opens the file with no problems. Has anyone else come across this 'clash' of Excel not opening properly when VFP is open?
I have no problems opening simultaneous sessions of VFP and Excel before my program runs, so I guess it is not closing Excel properly, despite the fact that there is an oXL.quit command near the end of the program.
Here is the code...
PUBLIC oXL && cannot be LOCAL in this case
oXL = CREATEOBJECT("Excel.Application") && Start Excel
oXL.Workbooks.Add && create a workbook
oXL.ActiveWorkbook.SaveAs('MySheet') && assign name
* Fill cell contents of sheet 1 here
* Close spreadsheet
oXL.ActiveWorkBook.Save
oXL.Quit && quit Excel
2. The OLE-created spreadsheet by default has 3 sheets. Do I have to delete sheets 2 and 3 programmatically, or is there a way to create the workbook with one sheet only? Come to think of it, do I have to create a workbook at all? Can I create a single sheet by itself?
Any help would be appreciated.
Alan
Next
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