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:
01102232
Views:
18
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.

>>Thanks Craig for your very comprehensive answer.
>>I am getting an error on this line:
>>
>>
loDestinationWrkBk.Save()
>>
>>OLE IDispatch exception code 0 from Microsoft Excel: Unable to get the Save property of the Application class..
>>
>>Does this look like a code error, or something I'm doing wrong in my testing?
>>
>>Thanks again
>>Cyril
>
>Sorry about that Cyril. I should have just taken the extra 2 minutes to test the code that I pulled so you didn't have to take the time to debug it. Anyways, I've made a couple of changes to the code and run some simple test to make sure it works now. The code will combine the first worksheet from several xls files into a new xls file that you specify.
>
>
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, lnSheetCount, lcWorkSheetCaption
>	loDestinationWrkBk = NEWOBJECT("Excel.Application")
>	loDestinationWrkBk.ScreenUpdating = .F.
>	loDestinationWrkBk.DisplayAlerts = .F.
>	loDestinationWrkBk.Workbooks.Open(taXLSFiles(1,1))
>	lnCounter = 0
>	FOR EACH loWorkSheet IN loDestinationWrkBk.Workbooks(1).WorkSheets
>		lnCounter = lnCounter + 1
>		IF lnCounter > 1
>			loWorkSheet.Delete
>		ENDIF
>	ENDFOR
>	lcWorkSheetCaption = JUSTSTEM(taXLSFiles(1))
>	loDestinationWrkBk.Workbooks(1).ActiveSheet.Name = RIGHT(ALLTRIM(CHRTRAN(lcWorkSheetCaption,CHRTRAN(lcWorkSheetCaption,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ","")," ")), 31) &&loWorkBook.Name
>	lnSheetCount = loDestinationWrkBk.Workbooks(1).Worksheets.Count
>	FOR lnCounter = 2 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.Save(tcDestination)
>	loDestinationWrkBk.ScreenUpdating = .T.
>	loDestinationWrkBk.DisplayAlerts = .T.
>	loDestinationWrkBk.Quit()
>ENDFUNC
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform