Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linking styles and numbering using VBA

Posted on 2011-09-22
7
Medium Priority
?
418 Views
Last Modified: 2012-06-22
I have about 30 templates where I want to, using VBA, ensure that they have a consistent user-defined style and numbering format.  I managed to get the font and sizing correct for the style, but the numbering seems to be a separate beast.  Can anyone supply VBA code that says, "when I apply this style, use this numbering".  Basically, like how it works when you use the built-in "Header1" or "Header2" style format.  But for me in a custom style.

Thanks!
0
Comment
Question by:ajakeway
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 50
ID: 36579991
Hello,

why don't you include the numbering in the style definition?

cheers, teylyn
0
 
LVL 2

Author Comment

by:ajakeway
ID: 36580014
Teylyn,

I would love to.  I have spent two days searching online for how to do so.  Can you provide any code or website that might guide me on this?  Unfortunately the macro recorder hasn't helped me with this either.

Alex
0
 
LVL 50
ID: 36580094
Modify the style and select a numbering format.

Or are you defining the styles from scratch in VBA? If so, why? You might consider creating templates with the styles already defined and create documents based on these templates. Then the styles and their numbering will be in place without any VBA involvement.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Author Comment

by:ajakeway
ID: 36580115
Because I am modifying templates, I thought it best to define the styles from scratch in VBA.  That way there would be consistency between the templates, and I could use VBA to open each template, apply the required style (and numbering scheme) and then save the template.  I could do so manually, but I foresee us taking this approach for other documents (and templates) as well, so if possible, doing it via VBA would be nicer.
0
 
LVL 50

Accepted Solution

by:
Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 2000 total points
ID: 36580140
In Word 2010, the macro recorder creates this when modifying the Heading1 style and assigning the numbering format

A.
B.
C.

Sub Macro1()
'
' Macro1 Macro
'
'
    With ActiveDocument.Styles("Heading 1").ParagraphFormat
        .LeftIndent = CentimetersToPoints(1.27)
        .RightIndent = CentimetersToPoints(0)
        .SpaceBefore = 24
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceMultiple
        .LineSpacing = LinesToPoints(1.15)
        .Alignment = wdAlignParagraphLeft
        .WidowControl = True
        .KeepWithNext = True
        .KeepTogether = True
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = CentimetersToPoints(-0.63)
        .OutlineLevel = wdOutlineLevel1
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With
    ActiveDocument.Styles("Heading 1").NoSpaceBetweenParagraphsOfSameStyle = _
        False
    With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1)
        .NumberFormat = "%1."
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleUppercaseLetter
        .NumberPosition = CentimetersToPoints(0.63)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = CentimetersToPoints(1.27)
        .TabPosition = wdUndefined
        .ResetOnHigher = 0
        .StartAt = 1
        With .Font
            .Bold = wdUndefined
            .Italic = wdUndefined
            .StrikeThrough = wdUndefined
            .Subscript = wdUndefined
            .Superscript = wdUndefined
            .Shadow = wdUndefined
            .Outline = wdUndefined
            .Emboss = wdUndefined
            .Engrave = wdUndefined
            .AllCaps = wdUndefined
            .Hidden = wdUndefined
            .Underline = wdUndefined
            .Color = wdUndefined
            .Size = wdUndefined
            .Animation = wdUndefined
            .DoubleStrikeThrough = wdUndefined
            .Name = ""
        End With
        .LinkedStyle = "Heading 1"
    End With
    ActiveDocument.Styles("Heading 1").LinkToListTemplate ListTemplate:= _
        ListGalleries(wdNumberGallery).ListTemplates(1), ListLevelNumber:=1
    With ActiveDocument.Styles("Heading 1")
        .AutomaticallyUpdate = False
        .BaseStyle = "Normal"
        .NextParagraphStyle = "Normal"
    End With
End Sub

Open in new window


I guess the crucial commands are

   With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1)
        .NumberFormat = "%1."
        .TrailingCharacter = wdTrailingTab
       .NumberStyle = wdListNumberStyleUppercaseLetter
0
 
LVL 2

Author Comment

by:ajakeway
ID: 36601450
my apologies, I got tied up with kids duty and then other work became a priority.

As for this... I tried the suggested VBA and it would work in one template but not another.  I believe this is because of differences between the numbering formats in the various templates.  With the reply above and the various other online sources detailing how numbering lists work and the rather, uh, ingenious ways that WORD handles them and styles, I have decided to try approaching this from another way.  If I find a solution, I will post it.  For now, the question is deemed closed.
0
 
LVL 2

Author Closing Comment

by:ajakeway
ID: 36601459
Considering the complexity of styles and numbering lists in Word, the solution provided appropriate guidance.  Ultimately I will need to take a different approach.
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
New style of hardware planning for Microsoft Exchange server.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question