Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21839

[RESOLVED] Object Varialbe or With Block Not Set

$
0
0
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

Code:

  '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

2) User closes Excel using "X" on Excel Form
3) User then closes the VB App which executes the following code:

Code:

        oxlApp.ActiveWorkbook.Close False
4) Error: "Object Varialbe or With Block Not Set" is then raised because object is no longer valid.

5) NOTE: For whatever reason oxlApp.Quit can be executed without raising the above error.

Viewing all articles
Browse latest Browse all 21839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>