PDA

View Full Version : advise on nameing numberlist



qr_doc_con
06-15-2011, 05:08 AM
Hi everyone,

Need some advise on nameing my numberlist.

What i've got is a command button that runs the code below to add a numberlist to the style guide.

I've got it working so that it counts all the styles and adds 1 to that number then adds that to the end of the numberlist name. What i would like to have is it to start at 1 and increase each time a new list is added.

any advise would be great.

Public Sub DefineMyListNumberingAndStyle()
Dim oListTemplate As ListTemplate
Dim sListTemplateName As String

stycount = ActiveDocument.Styles.Count
lstnum = stycount + 1

'put the name right at the top, in case you later
'decide to have more than 1-- easier to change the code
sListTemplateName = "oListNumberTemplate" & CStr(lstnum)

On Error Resume Next
Set oListTemplate = ActiveDocument.ListTemplates(sListTemplateName)
'there will be an error if it didn't exist
If Err.Number <> 0 Then
Set oListTemplate = ActiveDocument.ListTemplates.Add(OutlineNumbered:=False)
oListTemplate.Name = sListTemplateName
End If
'reset the error trapping
On Error GoTo 0

'either way, you now have your list template at this point
'so define the heading styles
DefineHeadingStyles

'and your list template
DefineListTemplate oListTemplate
End Sub
Public Sub DefineHeadingStyles()
Dim fontRGB As Long
Dim stycount As Long
Dim listnum As Integer
stycount = ActiveDocument.Styles.Count
lstnum = stycount + 1
ActiveDocument.Styles.Add ("numberlist " & CStr(lstnum))

fontRGB = RGB(80, 80, 180) 'set border colour variable based on Red/Green/Blue colour code
With ActiveDocument.Styles("numberlist " & CStr(lstnum))
.AutomaticallyUpdate = False
.BaseStyle = "Normal"
.NextParagraphStyle = "Normal"
With .Font
.Bold = True ' turns on Bold Text
.Italic = False ' turns off Italic Text
.Color = fontRGB 'Change font to Grey via variable
.AllCaps = False 'Remove all caps
.Size = 11 ' sets font size
.Name = "arial" 'sets type of font
End With
With .ParagraphFormat
.Alignment = wdAlignParagraphLeft 'Align to left
.SpaceBefore = 12 ' sets the paragraph spacing above the text
.SpaceAfter = 6 ' sets the paragraph spacing below the text
.LineSpacing = 12 ' sets line spacing to single
End With
End With

End Sub
'pass in the list template, muck with the definitions here
Public Sub DefineListTemplate(oListTemplate As ListTemplate)

lstnum = ActiveDocument.Styles.Count

With oListTemplate.ListLevels(1)
.NumberFormat = "%1)"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleLowercaseLetter
.NumberPosition = InchesToPoints(0) ' adjust indent here
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.25)
.ResetOnHigher = 0 'this must be zero
.StartAt = 1
.LinkedStyle = "numberlist " & CStr(lstnum)
End With
End Sub