Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel copy sheet data from one file to another
Message
 
À
16/09/2014 10:24:34
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01607618
Message ID:
01607779
Vues:
29
>>Hi all
>>
>>I have some Excel automation code (see below) which works to an extent. What it does is opens a xls file and does a SaveAs() xlsx file in case such a target file is not found. Then I try to open both these files and I need to copy the first sheet in the xls into the xlsx first sheet but the Paste() seems to fail for me.
>>
>>Please advise on how can I get the updated data from the old format to the new format.
>>
>>Kind regards
>>Bhavbhuti
>>
>>
>>lcXLS = (MyOldExcelFormatFilePathName)
>>lcXLSX = lcXLS + "X"
>>
>>
>>loExcel = CREATEOBJECT("Excel.Application")
>>
>>IF VARTYPE(loExcel) <> "O"
>>	MESSAGEBOX("Cannot start Excel to convert file to XLSX")
>>	
>>	RETURN
>>ENDIF
>>
>>*loExcel.Visible = .F.
>>
>>
>>loWBOld = loExcel.Application.WorkBooks.Open(lcXLS)
>>
>>IF NOT FILE(lcXLSX)
>>	loWBOld.SaveAs(lcXLSX, 51)
>>ENDIF
>>
>>
>>loWBNew = loExcel.Application.WorkBooks.Open(lcXLSX)
>>
>>
>>*** copy the first sheet from old to new
>>loExcel.WINDOWS(JUSTFNAME(lcXLS)).ACTIVATE
>>loExcel.Sheets(JUSTFNAME(lcXLS)).Copy(loWBOld.Sheets(1))
>>
>>loExcel.WINDOWS(JUSTFNAME(lcXLSX)).ACTIVATE
>>loWBNew.Paste()
>>
>>
>>loWBOld.Close()
>>loWBNew.Close()
>>
>>loWBOld = NULL
>>loWBNew = NULL
>>loExcel = NULL
>>
>
>
>You probably need to paste to the worksheet, not the workbook.
>
>Tamar

Thanks Tamar. I tried that no joy. Further looking into it seems the Copy command itself is not working. If there a VFP code somewhere that copies all the data from the first sheet and then paste, I could probably adapt for my usage.

Kind regards
Bhavbhuti
Regards
Bhavbhuti
___________________________________________
Softwares for Indian Businesses at:
http://venussoftop.tripod.com
___________________________________________
venussoftop@gmail.com
___________________________________________
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform