Editing Paragraph Line Spacing using macro; need help

  • Follow


I have the following code which should, but does not, change paragraphs that 
have exactly 24 or 12 pt spacing.

Can you advise me as to what is wrong with the code?  I can't find anything 
that addresses the issue in an if statement.  I hope someone can help.

Sub ParaSpacingFix3()
'2. If the paras is set to exactly 12 points
'       then make the spacing single spaced.
'   If the paras is set to exactly 24 points
'       then make the spacing double spaced.
Dim par As Paragraph

On Error GoTo NextPara

For Each par In ActiveDocument.Paragraphs
    If par.LineSpacingRule = wdLineExactly Then
        If par.LineSpacing = 24 Then
            par.LineSpacingRule = wdLineSpaceDouble
        ElseIf par.LineSpacing = 12 Then
            par.LineSpacingRule = wdLineSpaceSingle
        End If
    End If
    
NextPara:
Next

End Sub
0
Reply Utf 2/23/2010 2:55:01 PM

Use
If par.LineSpacingRule = wdLineSpaceExactly Then
or
If par.LineSpacingRule = 4 Then

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

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


"CJ" <CJ@discussions.microsoft.com> wrote in message 
news:7272BD13-2EFA-4AB1-9DF5-2D856590F6B1@microsoft.com...
>I have the following code which should, but does not, change paragraphs 
>that
> have exactly 24 or 12 pt spacing.
>
> Can you advise me as to what is wrong with the code?  I can't find 
> anything
> that addresses the issue in an if statement.  I hope someone can help.
>
> Sub ParaSpacingFix3()
> '2. If the paras is set to exactly 12 points
> '       then make the spacing single spaced.
> '   If the paras is set to exactly 24 points
> '       then make the spacing double spaced.
> Dim par As Paragraph
>
> On Error GoTo NextPara
>
> For Each par In ActiveDocument.Paragraphs
>    If par.LineSpacingRule = wdLineExactly Then
>        If par.LineSpacing = 24 Then
>            par.LineSpacingRule = wdLineSpaceDouble
>        ElseIf par.LineSpacing = 12 Then
>            par.LineSpacingRule = wdLineSpaceSingle
>        End If
>    End If
>
> NextPara:
> Next
>
> End Sub 


0
Reply Graham 2/23/2010 3:50:58 PM


Thank you Graham for pointing out my typo.  Works now. I'd love to be able to 
refer to the linespacing rules values, how do I find out what the other ones 
are.

"Graham Mayor" wrote:

> Use
> If par.LineSpacingRule = wdLineSpaceExactly Then
> or
> If par.LineSpacingRule = 4 Then
> 
> -- 
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor -  Word MVP
> 
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> 
> 
> "CJ" <CJ@discussions.microsoft.com> wrote in message 
> news:7272BD13-2EFA-4AB1-9DF5-2D856590F6B1@microsoft.com...
> >I have the following code which should, but does not, change paragraphs 
> >that
> > have exactly 24 or 12 pt spacing.
> >
> > Can you advise me as to what is wrong with the code?  I can't find 
> > anything
> > that addresses the issue in an if statement.  I hope someone can help.
> >
> > Sub ParaSpacingFix3()
> > '2. If the paras is set to exactly 12 points
> > '       then make the spacing single spaced.
> > '   If the paras is set to exactly 24 points
> > '       then make the spacing double spaced.
> > Dim par As Paragraph
> >
> > On Error GoTo NextPara
> >
> > For Each par In ActiveDocument.Paragraphs
> >    If par.LineSpacingRule = wdLineExactly Then
> >        If par.LineSpacing = 24 Then
> >            par.LineSpacingRule = wdLineSpaceDouble
> >        ElseIf par.LineSpacing = 12 Then
> >            par.LineSpacingRule = wdLineSpaceSingle
> >        End If
> >    End If
> >
> > NextPara:
> > Next
> >
> > End Sub 
> 
> 
> .
> 
0
Reply Utf 2/23/2010 9:04:02 PM

The values are

wdLineSpaceSingle     0

wdLineSpace1pt5        1

wdLineSpaceDouble    2

wdLineSpaceMultiple 2

wdLineSpaceAtLeast   3

wdLineSpaceExactly    4



However using the names makes the macro easier to follow


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

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




"Dorak" <Dorak@discussions.microsoft.com> wrote in message 
news:9A9D60CB-E40A-4F8E-960C-880FB5A24008@microsoft.com...
> Thank you Graham for pointing out my typo.  Works now. I'd love to be able 
> to
> refer to the linespacing rules values, how do I find out what the other 
> ones
> are.
>
> "Graham Mayor" wrote:
>
>> Use
>> If par.LineSpacingRule = wdLineSpaceExactly Then
>> or
>> If par.LineSpacingRule = 4 Then
>>
>> -- 
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor -  Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> "CJ" <CJ@discussions.microsoft.com> wrote in message
>> news:7272BD13-2EFA-4AB1-9DF5-2D856590F6B1@microsoft.com...
>> >I have the following code which should, but does not, change paragraphs
>> >that
>> > have exactly 24 or 12 pt spacing.
>> >
>> > Can you advise me as to what is wrong with the code?  I can't find
>> > anything
>> > that addresses the issue in an if statement.  I hope someone can help.
>> >
>> > Sub ParaSpacingFix3()
>> > '2. If the paras is set to exactly 12 points
>> > '       then make the spacing single spaced.
>> > '   If the paras is set to exactly 24 points
>> > '       then make the spacing double spaced.
>> > Dim par As Paragraph
>> >
>> > On Error GoTo NextPara
>> >
>> > For Each par In ActiveDocument.Paragraphs
>> >    If par.LineSpacingRule = wdLineExactly Then
>> >        If par.LineSpacing = 24 Then
>> >            par.LineSpacingRule = wdLineSpaceDouble
>> >        ElseIf par.LineSpacing = 12 Then
>> >            par.LineSpacingRule = wdLineSpaceSingle
>> >        End If
>> >    End If
>> >
>> > NextPara:
>> > Next
>> >
>> > End Sub
>>
>>
>> .
>> 


0
Reply Graham 2/24/2010 7:31:49 AM

Thank you so much Graham, if I see the values like this in the future I will 
have something to refer to.

"Graham Mayor" wrote:

> The values are
> 
> wdLineSpaceSingle     0
> 
> wdLineSpace1pt5        1
> 
> wdLineSpaceDouble    2
> 
> wdLineSpaceMultiple 2
> 
> wdLineSpaceAtLeast   3
> 
> wdLineSpaceExactly    4
> 
> 
> 
> However using the names makes the macro easier to follow
> 
> 
> -- 
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor -  Word MVP
> 
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> 
> 
> 
> 
> "Dorak" <Dorak@discussions.microsoft.com> wrote in message 
> news:9A9D60CB-E40A-4F8E-960C-880FB5A24008@microsoft.com...
> > Thank you Graham for pointing out my typo.  Works now. I'd love to be able 
> > to
> > refer to the linespacing rules values, how do I find out what the other 
> > ones
> > are.
> >
> > "Graham Mayor" wrote:
> >
> >> Use
> >> If par.LineSpacingRule = wdLineSpaceExactly Then
> >> or
> >> If par.LineSpacingRule = 4 Then
> >>
> >> -- 
> >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >> Graham Mayor -  Word MVP
> >>
> >> My web site www.gmayor.com
> >> Word MVP web site http://word.mvps.org
> >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >>
> >>
> >> "CJ" <CJ@discussions.microsoft.com> wrote in message
> >> news:7272BD13-2EFA-4AB1-9DF5-2D856590F6B1@microsoft.com...
> >> >I have the following code which should, but does not, change paragraphs
> >> >that
> >> > have exactly 24 or 12 pt spacing.
> >> >
> >> > Can you advise me as to what is wrong with the code?  I can't find
> >> > anything
> >> > that addresses the issue in an if statement.  I hope someone can help.
> >> >
> >> > Sub ParaSpacingFix3()
> >> > '2. If the paras is set to exactly 12 points
> >> > '       then make the spacing single spaced.
> >> > '   If the paras is set to exactly 24 points
> >> > '       then make the spacing double spaced.
> >> > Dim par As Paragraph
> >> >
> >> > On Error GoTo NextPara
> >> >
> >> > For Each par In ActiveDocument.Paragraphs
> >> >    If par.LineSpacingRule = wdLineExactly Then
> >> >        If par.LineSpacing = 24 Then
> >> >            par.LineSpacingRule = wdLineSpaceDouble
> >> >        ElseIf par.LineSpacing = 12 Then
> >> >            par.LineSpacingRule = wdLineSpaceSingle
> >> >        End If
> >> >    End If
> >> >
> >> > NextPara:
> >> > Next
> >> >
> >> > End Sub
> >>
> >>
> >> .
> >> 
> 
> 
> .
> 
0
Reply Utf 2/24/2010 2:46:05 PM

4 Replies
2977 Views

(page loaded in 0.2 seconds)

Similiar Articles:
















7/18/2012 6:40:17 PM


Reply: