Posts: 32
Threads: 10
Joined: Feb 2009
Hello,
I'm reading cells in a hidden excel sheet and it works great, but i have one problem..
Function is called from a dialog proc, and it seems that connection still exist untill the dialog is closed.
If i open excel file manually, i'm getting the message that it's allready open and then an empty window..
But it should be closed, or what:
wb.Saved=TRUE; err
wb.Application.Quit
Thanks for any help!
Joergen
Posts: 11,926
Threads: 138
Joined: Dec 2002
Macro
str f.expandpath("$personal$\book1.xls")
Excel.Application app._create
Excel.Workbook wb=app.Workbooks.Open(f)
Excel.Worksheet ws=wb.ActiveSheet
str s=ws.Range("A2").Value
out s
s+"A"
ws.Range("A2").Value=s
wb.Save
app.Quit
err+
,app.Quit
,end _error
;All excel variables should be destroyed or set to 0.
;Then you can open the file in Excel.
;It also closes the hidden excel process started by this macro.
;Instead of setting all variables to 0, you can move the above code to a separate function. If all variables are local, they are destroyed when the function ends.
ws=0
wb=0
app=0
15 ;;try to open the file in Excel now
another way
Macro
str f.expandpath("$personal$\book1.xls")
Excel.Workbook wb._getfile(f) ;;open file in background
Excel.Worksheet ws=wb.ActiveSheet
str s=ws.Range("A2").Value
out s
s+"A"
ws.Range("A2").Value=s
wb.Windows.Item(1).Visible=TRUE ;;without this the workbook would be hidden in Excel
wb.Save
wb.Application.Quit
ws=0
wb=0
15 ;;try to open the file in Excel now
Posts: 32
Threads: 10
Joined: Feb 2009
Thanks, Gintaras - i did try to set 'ws' and 'wb' to 0, but didn't think of the application variable...
But now i have descided to run the excel code in its own thread, started by 'mac' and a pointer to data structure.
Then waits for a flag to be set when data is ready. This works very well, and i don't have to think about destroying variables.
Joergen