Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combining XLS files into one workbook
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01035967
Message ID:
01102456
Views:
14
Something like that?
DIMENSION MyExcelFiles[5]
MyExcelFiles[1] = "c:\XlsF1.XLS"
MyExcelFiles[2] = "c:\XlsF2.XLS"
MyExcelFiles[3] = "c:\XlsF3.XLS"
MyExcelFiles[4] = "c:\XlsF4.XLS"
MyExcelFiles[5] = "c:\XlsF5.XLS"



FUNCTION CombineExcel(laExcelFiles, lcNewFileName)
    LOCAL oExcel AS Excel.Application
    LOCAL nXls, cActive, cNewBook
    oExcel = CREATEOBJECT("Excel.Application")
    oExcel.WorkBooks.New()
    oExcel.WorkBooks.SaveAs(lcNewFileName)
    cActive = oExcel.ActiveWorkbook.Name
    FOR nXLS = 1 TO ALEN(laExcelFiles,1)
        ** Because COPY TO XL produce only one sheet we must insert a new one here
        oExcel.ActiveWorkbook.Sheets.Add()
        oExcel.WorkBooks.Open(laExcelFiles[nXLS])
        cNewBook = oExcel.ActiveWorkbook.Name
        oExcel.ActiveWorkbook.ActiveSheet.Cells.Select()
        oExcel.Selection.Copy()
        oExcel.Windows(oActive).Activate
        oExcel.ActiveWorkbook.ActiveSheet.Paste()
        oExcel.Windows(cNewBook).Activate
        oExcel.ActiveWorkbook.Close()
        oExcel.Windows(oActive).Activate
    NEXT
    oExcel.ActiveWorkbook.Save()
    oExcel.Quit()
    oExcel = NULL
    RELEASE oExcel
RETURN
Not tested


>>>Sergey,
>>>
>>>Thanks for the tip! Now, who has done this and might you have some code you might be willing to share?
>>>
>>>Thanks!
>>
>>oExcel = CREATEOBJECT("Excel.Application")
>>DIMENSION MyExcelFiles[5]
>>MyExcelFiles[1] = "c:\XlsF1.XLS"
>>MyExcelFiles[2] = "c:\XlsF2.XLS"
>>MyExcelFiles[3] = "c:\XlsF3.XLS"
>>MyExcelFiles[4] = "c:\XlsF4.XLS"
>>MyExcelFiles[5] = "c:\XlsF5.XLS"
>>
>>oExcel.WorkBooks.Open(MyExcelFiles[1])
>>cActive = oExcel.ActiveWorkbook.Name
>>FOR nXLS = 2 TO 5
>>    ** Because COPY TO XL produce only one sheet we must insert a new one here
>>    oExcel.ActiveWorkbook.Sheets.Add()
>>    oExcel.WorkBooks.Open(MyExcelFiles[nXLS])
>>    cNewBook = oExcel.ActiveWorkbook.Name
>>    oExcel.ActiveWorkbook.ActiveSheet.Cells.Select()
>>    oExcel.Selection.Copy()
>>    oExcel.Windows(oActive).Activate
>>    oExcel.ActiveWorkbook.ActiveSheet.Paste()
>>    oExcel.Windows(cNewBook).Activate
>>    oExcel.ActiveWorkbook.Close()
>>    oExcel.Windows(oActive).Activate
>>NEXT
>>oExcel.ActiveWorkbook.Save()
>>oExcel.Quit()
>>oExcel = NULL
>>RELEASE oExcel
>>
>>Something like that
>
>Great code. But as I see in yours and Craig examples, you add new sheets with the informaiton to the first file, e.g. modifying the first Excel file. I was wondering if it's possible to do the same using a new clean file as output and don't touch the files from array?
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform