From: Tony Logan on
Is there a way I can write the below code without refering ActiveDocument?

ActiveDocument.Styles("Normal").NoSpaceBetweenParagraphsOfSameStyle = True

I'm out of practice with VBA, and am running it inside a VB script that
creates some Word templates. However, this line causes the script to bomb.

The following code works just fine:

Dim objSelection
Set objSelection = Word.Selection
objSelection.Font.Name = "Arial"
objSelection.Font.Size = "14"

My goal is somehow to make NoSpaceBetweenParagraphsOfSameStyle = True.

Thanks.
From: Graham Mayor on
How about

objSelection.Style.NoSpaceBetweenParagraphsOfSameStyle = True

but it will only work if all the selection is formatted in the same style so
applying a common style first should work eg

With objSelection
.Style = "Normal"
.Style.NoSpaceBetweenParagraphsOfSameStyle = True
.Font.name = "Arial"
.Font.Size = "14"
End With


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



Tony Logan wrote:
> Is there a way I can write the below code without refering
> ActiveDocument?
>
> ActiveDocument.Styles("Normal").NoSpaceBetweenParagraphsOfSameStyle =
> True
>
> I'm out of practice with VBA, and am running it inside a VB script
> that creates some Word templates. However, this line causes the
> script to bomb.
>
> The following code works just fine:
>
> Dim objSelection
> Set objSelection = Word.Selection
> objSelection.Font.Name = "Arial"
> objSelection.Font.Size = "14"
>
> My goal is somehow to make NoSpaceBetweenParagraphsOfSameStyle = True.
>
> Thanks.


From: wowens on

--
wowens


"Tony Logan" wrote:

> Is there a way I can write the below code without refering ActiveDocument?
>
> ActiveDocument.Styles("Normal").NoSpaceBetweenParagraphsOfSameStyle = True
>
> I'm out of practice with VBA, and am running it inside a VB script that
> creates some Word templates. However, this line causes the script to bomb.
>
> The following code works just fine:
>
> Dim objSelection
> Set objSelection = Word.Selection
> objSelection.Font.Name = "Arial"
> objSelection.Font.Size = "14"
>
> My goal is somehow to make NoSpaceBetweenParagraphsOfSameStyle = True.
>
> Thanks.