Setting break point (F9) causes macro to loop forever

T

Top Spin

I wrote the little macro shown below to increase the paragraph
"spacing before" setting by 6 points.

It works just fine unless I set a break point (F9) anywhere in the
macro. Then it loops forever. If I step through it (F8) or turn it
loose (F5), it goes right back to the Sub statement and runs over and
over.

What am I doing wrong?

Thanks

Here's the macro code:

----------------------------------------------------------
Sub IncLineSpaceBef6pts()
Dim setting As Single, reply As Long, msg As String

setting = Selection.ParagraphFormat.SpaceBefore

If setting < 999 Then 'If the selection is all the same setting,
'increase it by 6
Selection.ParagraphFormat.SpaceBefore = setting + 6
Else 'Otherwise, ask for instructions
msg = "The selection contains multiple Space Before settings. " _
& "Set them all to 6?"
reply = MsgBox(msg, vbYesNoCancel + vbDefaultButton2,
"SpaceBeforeToggle macro")
If reply = vbYes Then 'If they say yes, set them all to 6
Selection.ParagraphFormat.SpaceBefore = 6
End If 'Otherwise, do nothing
End If

End Sub
 
J

Jezebel

There's nothing obviously wrong in the code (not obvious to me, anyway).
What actually triggers the macro in the first place?
 
T

Top Spin

There's nothing obviously wrong in the code (not obvious to me, anyway).
What actually triggers the macro in the first place?

I have it assigned to a keyboard shortcut (Ctrl+{).

I open the VBA editor, set uop a break point (F9), hot key back to
Word, select some text, and type the Crtl+{.

The macro starts right up and will execute correctly. But when I
reached the last line, it loops back and starts again.

I also noticed that the "Reset" button on the VBA Editor toolbar (the
little blue square that stop execution) is never greyed out. In VB6,
it is only blue when a some VB code is running. This one is blue all
the time.
 
G

Gerry Knight

Do not run the code from Word for testing. If you want to use
breakpoints, run the code from the VBE. When you execute from Word
itself, it has no idea what to do with breakpoints. When code is compiled
for run-time (as it would be, called from Word) those breakpoints are
ignored. However, you have the VBE open, so it kinda tries. Select your
text in Word, go back to the VBE and run your code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top