How do I create a particular macro in Word 2007

Right now to create a numbered procedure I have to:

1, Select numbering from number icon of the form:

1.
2.
Etc

2 then I do left indent to make it flush left

3. Then I select spacing of 1.5.

Result:

1.

2.

etc.


Question: How can I do this with a macro?


bark1Asked:
Who is Participating?
 
GrahamSkanRetiredCommented:
Have you tried recording a macro. That should work, but the code will be unnecessarily long because it sets the default values for all possible properties.

So here is a simple macro:

 
Sub SetUpParagraphs()
    With Selection
       .Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
            ListGalleries(wdNumberGallery).ListTemplates(1)
        .ParagraphFormat.LeftIndent = CentimetersToPoints(0)
    End With
End Sub

Open in new window


However you could create a new style instead, which might be easier to use that a macro.

With the modified text selected, open the 'Styles' window with the tiny arrow at the bottom-right of the 'Styles' group on the 'Home' tab. The bottom-left icon on the 'Styles' window is the 'New Style' button.
0
 
bark1Author Commented:
Hi GrahamSkan,

Thanks for prompt response. Both methods you gave me work fine--up to a point. That is, when I go to start a new list, they both start with the continuous number from the old list-they do not start at 1required for the new procedure.
0
 
GrahamSkanRetiredCommented:
The .ApplyListTemplateWithLevel Method has an argument (ContinuePreviousList) for that

Sub SetUpParagraphs()
    With Selection
       .Range.ListFormat.ApplyListTemplateWithLevel _
            ListTemplate:=ListGalleries(wdNumberGallery).ListTemplates(1), _
            ContinuePreviousList:=False
        .ParagraphFormat.LeftIndent = CentimetersToPoints(0)
    End With
End Sub

Open in new window

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
bark1Author Commented:
Thanks.

Almost there.

I need line spacing of 1.5. Could you modify the code to do this?
0
 
GrahamSkanRetiredCommented:
LinsSpacing is a property of the ParagraphFormat object, but is measured in Points, so we need to convert the lines value into Points
Sub SetUpParagraphs()
    With Selection
       .Range.ListFormat.ApplyListTemplateWithLevel _
            ListTemplate:=ListGalleries(wdNumberGallery).ListTemplates(1), _
            ContinuePreviousList:=False
        With .ParagraphFormat
            .LeftIndent = CentimetersToPoints(0)
            .LineSpacing = LinesToPoints(1.5)
        End With
    End With
End Sub

Open in new window

0
 
bark1Author Commented:

Hi Graham,

I punched the VB code in and got an error I tried to run it. See attached file.

Thanks.

enus-1-.html
0
 
GrahamSkanRetiredCommented:
What is the number and text of the error message, and what line does it fail on, please? The link doesn't seem to be very relevant.

Also for the sake of future users, it is good to be able to use the text search to pick up errors, and it can't look inside pictures or links.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.