I've been annoyed by this for years, but now to try and do something about
Word 2002, currently under Vista HP (but it was the same behaviour under
Sometimes code does one thing (the wrong thing/nothing) when it runs
automatically, and does exactly the right thing when single-stepped - or is
otherwise odd in its execution! - making debugging impossible!
Current problem: I have a self re-starting on-time loop to handle idle
actions... to let me know that it is running in the background I have
created two alternate buttons on a custom toolbar and toggle their .visible
I can see the code setting the visible properties to the correct value, but
the buttons themselves often do not change visibility (they *do* seem to
change if I am watching in Word, but only at the point that I switch to the
VBA IDE... but this is not consistent behaviour: I *have* seen the icons
toggling away happily for hours...)
Buttons inited with e.g.
Set extrasBar = CommandBars("Extras")
Set idleLoopAButton = extrasBar.Controls("idleLoopA")
where idleLoopAButton is a module global.
The idle loop looks like this
Static Sub idleLoopActions()
Dim callCounter As Long
callCounter = callCounter + 1
On Error Resume Next
If idleLoopAButton.Visible = False And idleLoopAButton.Visible =
True Then ' dummy impossible test - only execute within if there is an
error accessing properties
On Error GoTo 0
If callCounter Mod 2 = 0 Then
idleLoopAButton.Visible = True ' just toggle the visibility
of two buttons
idleLoopBButton.Visible = False
idleLoopAButton.Visible = False
idleLoopBButton.Visible = True
' do other stuff omitted from post...
I have "cleaned" the code (with "VBA Code Cleaner", deleted the toolbars and
reimported them from a backup file... and restarted Word (NOT restarting the
VBA IDE) but all to no effect - buttons not toggling!
Does anyone have any ideas?
PS Code has lots of userforms, and some other ActiveX (a spreadsheet as OWC
Some Vista stuff, but mostly just Stuff at http://berossus,blogspot.com