Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hidden Excel
#1
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
#2
Macro
Code:
Copy      Help
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
Code:
Copy      Help
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
#3
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


Forum Jump:


Users browsing this thread: 1 Guest(s)