Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel Macro
Message
From
29/03/2000 11:40:00
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Miscellaneous
Thread ID:
00352122
Message ID:
00352164
Views:
10
Bill,
This will sound rather complex, but once you see it in a working system, it's not so bad, but this is what I do.

1. I have an excel file with a macro saved in it for formatting. NOTE: This macro requires a specific cursor structure, or it won't know where to find the proper data

2. I create my cursor and do a copy to which dumps this unformatted data into excel.

3. I then start up an instance of excel, into which I open up both the file that contains the macro, and the file I just did a 'COPY TO' with

&& Create instance of excel
excelsheet = createObject("excel.application")

&& Open workbook containing macro, but hide it
excelsheet.application.Workbooks.Open("C:\XLMacro.XLS")
excelsheet.ActiveWindow.Visible = .f.

&& Make excel visible and open the cursor you saved
excelsheet.application.visible = .t.
excelsheet.application.Workbooks.Open("C:\CopyTo.XLS")

4. I then run the macro, which (as mentioned earlier) is pre-programmed to know what sheets to look on for what data, and such. The macro adds a new sheet to the workbook, and scans through the data that you did a 'COPY TO' with using the cursors recordcount, and predetermined number of fields to control your looping. It then writes this data to the new sheet, and formats it as you dictated in the macro.

excelsheet.Application.Run("XLMacro.xls!MACRONAME")

5. When you're done, clean up your mess and save it.

excelsheet.application.displayalerts = .f.
&& Close the macro excelsheet
excelsheet.Windows("XlMacro.xls").Close

&& Save the new one as testResults.xls
delete file "c:\windows\desktop\testResults.xls"
excelsheet.activesheet.saveas("c:\windows\desktop\testResults.xls",43)
delete file "c:\windows\desktop\CopyTo.xls"
excelsheet.application.quit
release excelsheet
Paul A. Busbey
Victoria Insurance
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform