Discussion:
Style.NoSpaceBetweenParagraphsOfSameStyle Always Returning False?
(too old to reply)
Samuel Sunsmith
2008-10-08 18:11:01 UTC
Permalink
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
Klaus Linke
2008-10-08 20:44:44 UTC
Permalink
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
Post by Samuel Sunsmith
Document with multiple paragraphs (Normal Style)
the "Don't add space between paragraphs of the same style" checkbox is checked
Spacing Before is set to 15 pt
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
Samuel Sunsmith
2008-10-08 21:03:00 UTC
Permalink
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!
Post by 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
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
oStyle.NoSpaceBetweenParagraphsOfSameStyle = True
Debug.Print oStyle.NoSpaceBetweenParagraphsOfSameStyle
oStyle.NoSpaceBetweenParagraphsOfSameStyle = False
Debug.Print oStyle.NoSpaceBetweenParagraphsOfSameStyle
oStyle.ParagraphFormat.SpaceBefore = oldSpaceBefore
Regards,
Klaus
Post by Samuel Sunsmith
Document with multiple paragraphs (Normal Style)
the "Don't add space between paragraphs of the same style" checkbox is checked
Spacing Before is set to 15 pt
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
Doug Robbins - Word MVP
2008-10-08 22:13:42 UTC
Permalink
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
Post by Samuel Sunsmith
Document with multiple paragraphs (Normal Style)
the "Don't add space between paragraphs of the same style" checkbox is checked
Spacing Before is set to 15 pt
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
Samuel Sunsmith
2008-10-09 10:58:01 UTC
Permalink
Thanks Doug!

I can stop searching for what I won't be able to find.
Post by 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
Post by Samuel Sunsmith
Document with multiple paragraphs (Normal Style)
the "Don't add space between paragraphs of the same style" checkbox is checked
Spacing Before is set to 15 pt
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
Klaus Linke
2008-10-09 12:52:36 UTC
Permalink
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
Post by 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
Post by Samuel Sunsmith
Document with multiple paragraphs (Normal Style)
the "Don't add space between paragraphs of the same style" checkbox is checked
Spacing Before is set to 15 pt
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
Doug Robbins - Word MVP
2008-10-09 19:46:07 UTC
Permalink
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
Post by 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
Post by 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
Post by Samuel Sunsmith
Document with multiple paragraphs (Normal Style)
the "Don't add space between paragraphs of the same style" checkbox is checked
Spacing Before is set to 15 pt
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
Loading...