Odd behavior if Space Before is set to "Auto"

T

Top Spin

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

It works just fine except when the line spacing is set to "Auto". In
that case, the Selection.ParagraphFormat.SpaceBefore value is "5".

Why is that? I can't find anything "space before" or "Auto" in the
help file.

Since the macro isn't testing for "5", it goes ahead and increments it
by 6. This causes the setting to change as the macro reads it, but if
I click on Format / Paragraph, it still shows "Auto".

What the heck is going on here?

Thanks





Here's the 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
 
L

Luc

Hello Top Spin,
I asked a similar question about the meaning of the auto setting on the 15th
of March 2003 under the subject "Paragraph spacing" and got some interesting
answers from Suzanne S. Barnhill, Terry Farrell and Doug Robbins. If you
Google for it you should find it.
Luc
 
T

Top Spin

Hello Top Spin,
I asked a similar question about the meaning of the auto setting on the 15th
of March 2003 under the subject "Paragraph spacing" and got some interesting
answers from Suzanne S. Barnhill, Terry Farrell and Doug Robbins. If you
Google for it you should find it.
Luc

I found the article, but it does not seem to answer my questions,
which are:

1. What does the "Auto" setting do?

2. How can I detect it in a macro?

Thanks
 
K

Klaus Linke

1. What does the "Auto" setting do?

I think you found out about that already.

2. How can I detect it in a macro?

If Selection.ParagraphFormat.SpaceBeforeAuto = True Then '...

Regards,
Klaus
 
T

Top Spin

I think you found out about that already.



If Selection.ParagraphFormat.SpaceBeforeAuto = True Then '...

That works, but I the data type seems to be Long, not Boolean. The
following were executed in the Immediate window when the macro was in
break mode with the line set to "Auto".

?Selection.ParagraphFormat.SpaceBeforeAuto
-1

?typename(Selection.ParagraphFormat.SpaceBeforeAuto)
Long

Thanks for the solution.
 
T

Top Spin

I think you found out about that already.



If Selection.ParagraphFormat.SpaceBeforeAuto = True Then '...

Regards,
Klaus

The questions I should have asked is whether it is better to code the
test as

If Selection.ParagraphFormat.SpaceBeforeAuto = True

as you did and which is more self-documenting, or as

If Selection.ParagraphFormat.SpaceBeforeAuto = -1

since the property is of type Long.
 
K

Klaus Linke

The questions I should have asked is whether it is better to code the
test as

If Selection.ParagraphFormat.SpaceBeforeAuto = True

as you did and which is more self-documenting, or as

If Selection.ParagraphFormat.SpaceBeforeAuto = -1

since the property is of type Long.


Not sure... According to the Help, the property can be True, False, or
wdUndefined, and the Help example uses ".SpaceBeforeAuto = True".
So I guess it's ok/preferable to use True.

Greetings,
Klaus
 
T

Top Spin

Not sure... According to the Help, the property can be True, False, or
wdUndefined, and the Help example uses ".SpaceBeforeAuto = True".
So I guess it's ok/preferable to use True.

Where did you find this in the Help? Is this the regular help for
Word? I couldn't find anything.

Thanks
 
K

Klaus Linke

Where did you find this in the Help?

In the VBA editor, you can get help for any object, property, or method if
you put the cursor somewhere in the text (in this case of
".SpaceBeforeAuto"), and press F1.

:) Klaus
 
T

Top Spin

In the VBA editor, you can get help for any object, property, or method if
you put the cursor somewhere in the text (in this case of
".SpaceBeforeAuto"), and press F1.

OK. Thanks.

And where did you find out that ".SpaceBeforeAuto" even exists?
 
K

Klaus Linke

And where did you find out that ".SpaceBeforeAuto" even exists?

I typed Selection.ParagraphFormat.s
(the "s" since I guessed it might be something like "SpaceBefore...")
At that point, IntelliSense offered a list of available objects,
properties, and methods.

If that doesn't work, you may have to check stuff in "Tools > Options".

Or you can record changing the paragraph format's "SpaceBefore" to "Auto".
The code from the macro recorder is quite verbose since it records all the
formatting, not just what you changed.
But it's not too hard to find the relevant stuff.

Sometimes you can also look up some related object/property/method, and
then look what's listed under "See also" at the top of the help topic.
It doesn't work in this case though if I look up ".SpaceBefore" ...:
"SpaceBeforeAuto" isn't listed there.

Greetings,
Klaus
 
T

Top Spin

I typed Selection.ParagraphFormat.s
(the "s" since I guessed it might be something like "SpaceBefore...")
At that point, IntelliSense offered a list of available objects,
properties, and methods.

If that doesn't work, you may have to check stuff in "Tools > Options".

Or you can record changing the paragraph format's "SpaceBefore" to "Auto".

Of course. That would have been the obvious (just not to me) thing to
do. Thanks.
 

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