Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Releasing Excel
Message
From
11/05/2005 02:47:14
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
11/05/2005 01:38:26
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Environment versions
OS:
Windows XP
Miscellaneous
Thread ID:
01012715
Message ID:
01012723
Views:
24
>XP, VFP7 and Excel 2000
>
>I am having problems releasing the Excel object (process) after I have finished with the object. If I just create the object and then close again it works fine, but if I do anything like read a value or write to a sheet, in mosy instances it doesn't release the object properly (eg. If I use the Windows Taskmanager, the excel process will still be there).
>
>I have read posts on this site, advising to ensure that I release the object after using oExcel.quit(), and even assigning null to the object variable, which I have followed to the letter, but still the process still hangs in the sytem.
>
>Has anyone else any advise that may close the process after I have finished with it? Any help appreciated.
>
>Regards
>Darren

Darren,
If oExcel is not public it's sufficient IMHO.
ie:
VFP2Excel(home()+'samples\data\testdata.dbc','select * from employee',"Employees")

function VFP2Excel
lparameters tcDataSource, tcSQL, tcSheetName
Local loConn As AdoDB.Connection, ;
	loRS As AdoDB.Recordset,;
	lcTempRs as string, ;
	lcTemp as string, ;
	oExcel as Excel.Application

lcTempRs = Sys(5)+Curdir()+Sys(2015)+'.rst'
loConn = Createobject("Adodb.connection")
loConn.ConnectionString = "Provider=VFPOLEDB;Data Source="+m.tcDataSource
loConn.Open()
loRS = loConn.Execute(m.tcSQL)
loRS.Save(m.lcTempRs)
loRS.Close
loConn.Close
loRS.Open(m.lcTempRs)

oExcel = Createobject("Excel.Application")
With oExcel
	.WorkBooks.Add
	.Visible = .T.
	With .ActiveWorkBook.ActiveSheet
		.Name = m.tcSheetName
		.QueryTables.Add( loRS, .Range("A1")).Refresh()
		.Range("A1").AutoFormat(8) && xlRangeAutoFormatColor2
		.Range("A1").Activate
	Endwith
Endwith
loRs.Close
Erase (m.lcTempRS)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform