Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VBA Timer Events Suspend When Cursor is Positioned at the Start of Inline Math Zones #40

Open
brichwin opened this issue Nov 25, 2024 · 0 comments

Comments

@brichwin
Copy link
Collaborator

Description

When using the Equation Editor in Word 365, VBA timer events unexpectedly suspend their execution when the cursor is positioned at the very beginning of an inline math zone (immediately after entering the math zone).
screenshot of a word document with a sentence containing an inline math expression. The equation editor is visible and the input cursor can be seen just inside of the editor at the front of the math expression.
The timer events resume normal execution when either:

  • Moving the cursor outside the math zone, or
  • Moving the cursor further inside the math zone

A video demo of this behavior is available at: Video: VBA script gets suspended when the input cursor is at the beginning of an inline OMath expression (2 minutes)

This behavior does not occur with display math zones, only inline math zones.

Steps to Reproduce

  1. Create a Word document with an inline math expression (e.g., $\sqrt{x+5}$)
  2. Add a VBA timer that runs periodic events (example code below)
  3. Use the Immediate Window (Ctrl+G) or other means to monitor the timer
  4. Run the VBA code to start the timer
  5. Position the cursor at different locations:
    • Just before the math zone (timer runs normally)
    • At the very beginning of the math zone; editor visible & in front of expression (timer suspends)
    • Further inside the math zone (timer resumes)
    • Outside the math zone (timer runs normally)

Example Code

Dim lnCounter As Long
Dim blnEnableCounter As Boolean
Dim dtNextTime As Date
Const INTERVAL_SECONDS As Double = 0.1 ' 1/10th of a second

Sub startCounting()
    blnEnableCounter = True
    lnCounter = 0
    count
End Sub

Sub stopCounting()
    blnEnableCounter = False
End Sub

Sub count()
    If blnEnableCounter = True Then
        lnCounter = lnCounter + 1
        Debug.Print lnCounter
        ' Schedule the next count
        dtNextTime = Now + (INTERVAL_SECONDS / 86400) ' Convert seconds to days
        Application.OnTime When:=dtNextTime, Name:="count"
    End If
End Sub

Tested Version Information

Windows OS

OS Version:
-- OS Name: Microsoft Windows 11 Enterprise
-- Version: 10.0.22621 Build 22621
-- Locale: United States
Microsoft Word Version:
-- Microsoft 365 Apps for enterprise
-- Version 2410 (Build 18129.20158 Click-to-Run) Current Channel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant