Style.NoSpaceBetweenParagraphsOfSameStyle Always Returning False?

  • Thread starter Samuel Sunsmith
  • Start date
S

Samuel Sunsmith

Conditions:
Document with multiple paragraphs (Normal Style)
On each paragraph:
the "Don't add space between paragraphs of the same style" checkbox is checked
Spacing Before is set to 15 pt

VBA:
Execute:
Dim sTest As String
Dim vTest As Variant
Dim oStyle As Object

Set oStyle = Selection.Style
sTest = oStyle.NameLocal
vTest = oStyle.NoSpaceBetweenParagraphsOfSameStyle

vTest is ALWAYS FALSE

I used a Variant just to be sure that some other type wasn't being returned.

Look in Local Variables at oStyle and NoSpaceBetweenParagraphsOfSameStyle is
FALSE!

Is there something obvious I'm over looking.

BTW the Style is Normal.

Thanks in advance for your time and consideration.

Sam
 
K

Klaus Linke

Hi Samuel,

I just checked your code, and it seems you can't change the
"NoSpaceBetweenParagraphsOfSameStyle if the style doesn't have any space
before and after anyway (...which kind of makes sense):

Dim oStyle As Style
Dim oldSpaceBefore As Single


Set oStyle = ActiveDocument.Styles(wdStyleNormal)

' remember old "space before"
oldSpaceBefore = oStyle.ParagraphFormat.SpaceBefore

oStyle.ParagraphFormat.SpaceBefore = 6

' now, the property can definitely be changed:
oStyle.NoSpaceBetweenParagraphsOfSameStyle = True
Debug.Print oStyle.NoSpaceBetweenParagraphsOfSameStyle
oStyle.NoSpaceBetweenParagraphsOfSameStyle = False
Debug.Print oStyle.NoSpaceBetweenParagraphsOfSameStyle

' clean up:
oStyle.ParagraphFormat.SpaceBefore = oldSpaceBefore

Regards,
Klaus
 
S

Samuel Sunsmith

Hi Klaus,

I wasn't intending to change the value as much as I am trying to detect a
setting
and return it back to the user in a form with a bunch of other Paragraph
values
( a one stop display as it were).

That's why I'd set the Before value to 15 pt, then applied the No Space
Between.

Then I checked it with my code and it always returned FALSE,
I was expecting it to return TRUE.

I guess I don't understand how it's supposed to work...

Given that your code works, with setting it, I'm going to give it another try,
probably tomorrow and see what I find. I'll update this post with the
results...

Thanks!
 
D

Doug Robbins - Word MVP

That result would be returned because the Style property has no attributes.

While the .ParagraphFormat property of the Selection object does have
attributes, it does not seem that the attribute that you are interested in
is exposed to VBA

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
K

Klaus Linke

Hi Doug,

I think you may have been fooled by IntelliSense not working properly with
styles.
Of course paragraph styles have all the same properties (attributes) as
paragraphs?

Regards,
Klaus
 
D

Doug Robbins - Word MVP

Hi Klaus,

You are correct there, but I did not see the
..NoSpaceBetweenParagraphsOfSameStyle as an attribute of the
..ParagraphFormat item either and figured that being a recent addition to the
user interface, it might be one of the things that was not exposed to VBA.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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