Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel spreadsheets to one workbook
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7
Miscellaneous
Thread ID:
01101620
Message ID:
01102361
Views:
20
Thanks Craig,

Interesting program. I added it my collection of VFP-Excel tidbits!

Peter



>>Craig,
>>
>>Something is still wrong. Your new Excel file somehow holds the reference to the original file. When you delete your temp Excel files, you would not be able to open this new Excel file.
>>
>>The algorithm has to be changed, but I'm not sure how.
>>
>>Thanks again.
>>
>
>Here you go Naomi...
>
>
DIMENSION aXLSFiles(3)
>aXLSFiles(1) = "C:\temp1.xls"
>aXLSFiles(2) = "C:\temp2.xls"
>aXLSFiles(3) = "C:\temp3.xls"
>CombineExcelFiles(@aXLSFiles, "C:\XLSCombined.xls")
>
>FUNCTION CombineExcelFiles (taXLSFiles, tcDestination)
>	EXTERNAL ARRAY taXLSFiles
>	LOCAL loDestinationWrkBk as Excel.Application, ;
>		loWorkBook as EXCEL.Workbook, ;
>		loWorkSheet as EXCEL.Worksheet, ;
>		lnCounter, lcWorkSheetCaption
>	loDestinationWrkBk = NEWOBJECT("Excel.Application")
>	loDestinationWrkBk.ScreenUpdating = .F.
>	loDestinationWrkBk.DisplayAlerts = .F.
>	loDestinationWrkBk.Workbooks.Add()
>	lnCounter = 0
>	FOR lnCounter = 1 TO ALEN(taXLSFiles)
>		IF FILE(taXLSFiles(lnCounter))
>			lcWorkSheetCaption = JUSTSTEM(taXLSFiles(lnCounter))
>			loWorkBook = loDestinationWrkBk.Workbooks.Open(taXLSFiles(lnCounter))
>			loWorkBook.Worksheets(1).Copy(NULL, loDestinationWrkBk.Workbooks(1).Worksheets(loDestinationWrkBk.Workbooks(1).Worksheets.Count))
>			loDestinationWrkBk.Workbooks(1).ActiveSheet.Name = RIGHT(ALLTRIM(CHRTRAN(lcWorkSheetCaption,CHRTRAN(lcWorkSheetCaption,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ","")," ")), 31) &&loWorkBook.Name
>			loWorkBook.Close(.F.)
>		ENDIF
>	ENDFOR
>	loDestinationWrkBk.Workbooks(1).WorkSheets(1).Delete
>	loDestinationWrkBk.Workbooks(1).SaveAs(tcDestination)
>	loDestinationWrkBk.ScreenUpdating = .T.
>	loDestinationWrkBk.DisplayAlerts = .T.
>	loDestinationWrkBk.Quit()
>ENDFUNC
Peter Cortiel
Previous
Reply
Map
View

Click here to load this message in the networking platform