Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel copy sheet data from one file to another
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Excel copy sheet data from one file to another
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01607618
Message ID:
01607618
Views:
40
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
Regards
Bhavbhuti
___________________________________________
Softwares for Indian Businesses at:
http://venussoftop.tripod.com
___________________________________________
venussoftop@gmail.com
___________________________________________
Next
Reply
Map
View

Click here to load this message in the networking platform