Is there a solution to this when executing a program from VB (Excel for example) then closing Excel directly INSTEAD of closing the VB App which will close Excel.
For example:
1) Excel started using late binding
2) User closes Excel using "X" on Excel FormCode:'Test the attachment of any possible already running instances our our desired Office app 'If unsecussful then it will direct the code to execute the error handler - "MyError" Set oxlApp = GetObject(, "Excel.Application") 'Test if it failed If TypeName(oxlApp) = "Nothing" Then 'If it gets to here then we have been returned from the error handler 'So we will want to create a new instance of the application object Set oxlApp = CreateObject("Excel.Application") End If
3) User then closes the VB App which executes the following code:
4) Error: "Object Varialbe or With Block Not Set" is then raised because object is no longer valid.Code:oxlApp.ActiveWorkbook.Close False
5) NOTE: For whatever reason oxlApp.Quit can be executed without raising the above error.




Reply With Quote