Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:48:05+00:00 2026-06-12T13:48:05+00:00

In my VBA code, I get a runtime exception (say divide by zero) and

  • 0

In my VBA code, I get a runtime exception (say divide by zero) and after pressing ‘End’ in the error box, the VBA runtime gets stopped.

During this stop, my global Objects are getting cleared. I want these objects to retain their values. Because, when I start over again, since these objects are Nothing, I am having issues.

Is there any event in VBA which will get triggered when my runtime gets stopped?? Or is there any way to know whether VBA is still running or stopped?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:48:06+00:00Added an answer on June 12, 2026 at 1:48 pm

    In VBA, an unhandled exception clears global variables. So add error handlers to your VBA procedures.

    Here is a transcript of a session in the Immediate window, using the 2 procedures included below.

    MyGlobal = "foo"
    Call DemoDivideByZero
    ? Chr(39) & MyGlobal & Chr(39)
    ''
    
    MyGlobal = "foo"
    Call DemoDivideByZero2
    Error 11 (Division by zero) in procedure DemoDivideByZero2
    ? Chr(39) & MyGlobal & Chr(39)
    'foo'
    

    A procedure without an error handler …

    Public Sub DemoDivideByZero()
        Debug.Print 2 / 0
    End Sub
    

    A version with an error handler …

    Public Sub DemoDivideByZero2()
    
        Dim strMsg As String
    
    On Error GoTo ErrorHandler
    
        Debug.Print 2 / 0
    
    ExitHere:
        On Error GoTo 0
        Exit Sub
    
    ErrorHandler:
        strMsg = "Error " & Err.Number & " (" & Err.Description _
            & ") in procedure DemoDivideByZero2"
        Debug.Print strMsg
        GoTo ExitHere
    End Sub
    

    However I’m unsure whether including error handlers in your procedures will be enough to preserve your global variable values. I avoid using globals.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write VBA code which works on my Excel sheet. Range(A65536).End(xlUp).Row
After installing all latest windows updates my Excel VBA code is showing an automation
Anyway to get Access 2K Module (vba code) editor to show line numbers?
I have a VBA code where I compute the values of many variables (For
Without having to write VBA code, is there a way to maybe write a
I am writing some VBA code which manipulates an HTML document. The document is
I have some VBA code that needs to talk to a running c# application.
I am looking for some VBA code (algorithm) to match a list of GPS
I'm am trying to write vba code to fill out web-forms and click buttons
I have a method in my VBA code that needs to be assigned to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.