Bug in Excel VBA (Debug Mode + ANY Floating Point Operation => Overflow error)

Copper Contributor

Since couple of days, I am encountering a serious issue with Excel when I do anything in debug mode.  I looked for ways to report to MicroSoft, but a quick search didn't turn up any easy ways to directly report it.  Hoping someone here with good connections to MicroSoft can shed some light or help propagate the issue to MS.

 

Issue: When any VBA macro is run in debug mode, the first time it encounters a floating point operation, it results in a "Overflow" error. 

 

Excel Versions: Excel 16.29.1 (19091700).

Also replicated on different versions from 16.24 to 16.29. (Not reproduced in 16.23)

OS: Mac OS 10.14 to 10.14.6 (Mojave)

 

What I tried: Tried on different machines with slightly different Excel versions and OS versions.  Tried removing all Add-Ins, restart computer, close all other applications etc.

 

Problem Repeats when:

  • Program enters debug mode via a breakpoint - OR - program encounters first debug.print call
  • Any subsequent operation that accesses a variable declared as single/double, or any math that implicitly or explicitly invokes a floating point operation (division, power etc.) results in an Overflow error.

 

Test Code:

Here are a few test macros that I wrote. Tried several other variants to convince myself that debug mode + floating point is the issue.

 

Summary:

Seems like a very serious issue to me. I can no longer rely on any macros that I wrote and distributed to my users, unless I remove all debug statements anywhere in my code. Also, cannot use debugger any more.

 

Option Explicit

Sub Test_WithDouble()
    'Scenario: Original scenario.
    'Result: Error on MsgBox line
    'Guess:Once program encounters debug mode (either via a breakpoint or a call to debug.pring) - subsequently any operation that implicitly or explicitly uses a type conversion seems to give error
    Dim x As Double
    x = 1
    Debug.Print "Debug statement Used"
    MsgBox "x=" & x
End Sub

Sub Test_WithoutDebug()
    'Variation: What if debug.print is comented out
    'Result: No Error (As long as it is not run in debug mode)
    'Guess:No issue unless debug mode is encountered
    'If you use a breakpoint on x=1 line, it DOES throw overflow error
    Dim x As Double
    x = 1
    'Debug.Print "Debug statement Used"
    MsgBox "x=" & x
End Sub

Sub Test_WithDebugVariant()
    'Variation: What if x is variant?
    'Result: No error
    'Guess: Perhaps no coersion of type
    Dim x As Variant
    x = 1
    Debug.Print "Debug statement Used"
    MsgBox "x=" & x
End Sub

Sub Test_WithDebugLong()
    'Variation: What if x is variant?
    'Result: No error
    'Guess: Perhaps no coersion of type
    Dim x As Long
    x = 1
    Debug.Print "Debug statement Used"
    MsgBox "x=" & x
End Sub

Sub Test_WithDebugString()
    'Variation: What if x is String?
    'Result: No error
    'Guess: Perhaps no coersion of type
    Dim x As String
    x = "1"
    Debug.Print "Debug statement Used"
    MsgBox "x=" & x
End Sub

Sub Test_WithDebugInteger()
    'Variation: What if x is Integer?
    'Result: No error
    'Guess: Perhaps no coersion of type
    Dim x As Integer
    x = 1
    Debug.Print "Debug statement Used"
    MsgBox "x=" & x
End Sub

Sub Test_WithDebugSingle()
    'Variation: What if x is Single?
    'Result: Error on MsgBox line
    'Guess: Perhaps no coersion of type
    Dim x As Single
    x = 1
    Debug.Print "Debug statement Used"
    MsgBox "x=" & x
End Sub

 

0 Replies