Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel Macro
Message
De
29/03/2000 11:40:00
 
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Titre:
Divers
Thread ID:
00352122
Message ID:
00352164
Vues:
11
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform