Hi, I'm learning how to do automation tasks with Excel .
In the MSDN
http://msdn.microsoft.com/it-it/library/microsoft.office.tools.excel.workbook.shutdown%28VS.80%29.aspxthere are lot's of events regarding WorkBooks .
I would like to understand ho to use (adding my code) one of those.
There's an interesting article about OLE Automation
http://www.dfpug.de/loseblattsammlung/migration/whitepapers/foxole.htmfrom where I've copied and pasted some code with little modification :
o=CREATEOBJECT("myExcel")
*o.visible=.T. && If I decomment appears an error
*o.Quit()
o=.null.
DEFINE CLASS myExcel AS OLEApplication
cOLERegName = "Excel.Application"
FUNCTION Destroy()
MESSAGEBOX("Chiudo") && some my code here
IF TYPE("this.oOLEApp") == "O" AND this.lCloseAppWhenDone
this.oOLEApp.Quit()
ENDIF
ENDFUNC
ENDDEFINE
DEFINE CLASS OLEApplication AS Custom
PROTECTED oOLEApp, cOLERegName, lCloseAppWhenDone
oOLEApp = ""
cOLERegName = ""
lCloseAppWhenDone = .T.
FUNCTION Init()
IF EMPTY(this.cOLERegName)
=MESSAGEBOX("Cannot create object directly from class OLEApplication", MB_ICONSTOP, "")
RETURN .F.
ENDIF
IF this.AppRunning()
this.oOLEApp = this.GetCurrentInstance()
ELSE
this.oOLEApp = this.CreateNewInstance()
ENDIF
ENDFUNC
PROTECTED FUNCTION CreateNewInstance()
RETURN CREATEOBJECT(this.cOLERegName)
ENDFUNC
PROTECTED FUNCTION GetCurrentInstance()
RETURN GETOBJECT(, this.cOLERegName)
ENDFUNC
PROTECTED FUNCTION AppRunning()
*— Returns .T. if app is already running
LOCAL lcOldError, llRunning
llRunning = .T.
lcOldError = ON("ERROR")
ON ERROR llRunning = .F.
=GETOBJECT(, this.cOLERegName) &&Attempt to get a reference to a running application
ON ERROR &lcOldError
this.lCloseAppWhenDone = !llRunning
RETURN llRunning
ENDFUNC
ENDDEFINE
If I run the code and look the list of processes in the task manager I see that
before the click on the MessageBox it show that Excel is working, and after the click it disappear
so it runs like I expect.
But if I decomment the line *o.visible=.T. I get the error "Property VISIBLE is not found"
What I am missing ?
Thank's in advance for help me understand this
Regards
Alberto