qr_doc_con
06-06-2011, 04:25 AM
I've setup a module to update the outline number list headings styles in word.
I need to have it working in both word 2003 and 2010 as I have mixture of both versions in the organisation and only want 1 lot of code.
I can set it up so that the code will works for each version seperatly but the final outcome I would like to have is one common source file.
Is there a way to have it so that this will work in both versions from the one module.
here is the code that i'm using
Public Sub outline_headings()
Dim fontRGB As Long
fontRGB = RGB(80, 80, 80) 'set border colour variable based on Red/Green/Blue colour code
On Error Resume Next
Call Heading_Style
ActiveDocument.Styles.Add ("Heading 1")
With ActiveDocument.Styles("Heading 1").Font
.Bold = True ' turns on Bold Text
.Color = fontRGB 'Change font to Grey
.AllCaps = False 'Remove all caps
.Size = 18 ' sets font size
.Name = "arial" 'sets type of font
End With
With ActiveDocument.Styles("Heading 1").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
With .Borders(wdBorderBottom) 'selects bottom border
.LineStyle = wdLineStyleSingle 'sets bottom border to single line
.LineWidth = wdLineWidth100pt ' sets line with to 1 point
.Color = fontRGB ' sets colour of line from font varible
End With
End With
ActiveDocument.Styles.Add ("Heading 2")
With ActiveDocument.Styles("Heading 2").Font
.Color = fontRGB 'Change font to Grey
.AllCaps = False 'Remove all caps
.Size = 16 ' sets font size
.Name = "arial" 'sets type of font
End With
With ActiveDocument.Styles("Heading 2").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
ActiveDocument.Styles.Add ("Heading 3")
With ActiveDocument.Styles("Heading 3").Font
.Color = fontRGB 'Change font to Grey
.AllCaps = False 'Remove all caps
.Size = 14 ' sets font size
.Name = "arial" 'sets type of font
End With
With ActiveDocument.Styles("Heading 3").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
ActiveDocument.Styles.Add ("Heading 4")
With ActiveDocument.Styles("Heading 4").Font
.Color = fontRGB 'Change font to Grey
.AllCaps = False 'Remove all caps
.Size = 12 ' sets font size
.Name = "arial" 'sets type of font
End With
With ActiveDocument.Styles("Heading 4").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
' 2010 code to have this working
ListGalleries(wdOutlineNumberGallery).ListTemplates(1).Name = ""
Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
ListGalleries(wdOutlineNumberGallery).ListTemplates(1), _
ContinuePreviousList:=False, ApplyTo:=wdListApplyToWholeList, _
DefaultListBehavior:=wdWord10ListBehavior
' 2003 code to have this working
ListGalleries(wdOutlineNumberGallery).ListTemplates(1).Name = ""
Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
wdOutlineNumberGallery).ListTemplates(5), ContinuePreviousList:=False, _
ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
End Sub
Sub Heading_Style()
With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(1)
.NumberFormat = "%1.0"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.25)
.ResetOnHigher = 0
.StartAt = 1
.LinkedStyle = "Heading 1"
End With
With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(2)
.NumberFormat = "%1.%2"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0.25)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.5)
.ResetOnHigher = 1
.StartAt = 1
.LinkedStyle = "Heading 2"
End With
With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(3)
.NumberFormat = "%1.%2.%3"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0.5)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.75)
.ResetOnHigher = 1
.StartAt = 1
.LinkedStyle = "Heading 3"
End With
With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(4)
.NumberFormat = "%1.%2.%3.%4"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0.75)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(1)
.ResetOnHigher = 1
.StartAt = 1
.LinkedStyle = "Heading 4"
End With
End Sub
I need to have it working in both word 2003 and 2010 as I have mixture of both versions in the organisation and only want 1 lot of code.
I can set it up so that the code will works for each version seperatly but the final outcome I would like to have is one common source file.
Is there a way to have it so that this will work in both versions from the one module.
here is the code that i'm using
Public Sub outline_headings()
Dim fontRGB As Long
fontRGB = RGB(80, 80, 80) 'set border colour variable based on Red/Green/Blue colour code
On Error Resume Next
Call Heading_Style
ActiveDocument.Styles.Add ("Heading 1")
With ActiveDocument.Styles("Heading 1").Font
.Bold = True ' turns on Bold Text
.Color = fontRGB 'Change font to Grey
.AllCaps = False 'Remove all caps
.Size = 18 ' sets font size
.Name = "arial" 'sets type of font
End With
With ActiveDocument.Styles("Heading 1").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
With .Borders(wdBorderBottom) 'selects bottom border
.LineStyle = wdLineStyleSingle 'sets bottom border to single line
.LineWidth = wdLineWidth100pt ' sets line with to 1 point
.Color = fontRGB ' sets colour of line from font varible
End With
End With
ActiveDocument.Styles.Add ("Heading 2")
With ActiveDocument.Styles("Heading 2").Font
.Color = fontRGB 'Change font to Grey
.AllCaps = False 'Remove all caps
.Size = 16 ' sets font size
.Name = "arial" 'sets type of font
End With
With ActiveDocument.Styles("Heading 2").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
ActiveDocument.Styles.Add ("Heading 3")
With ActiveDocument.Styles("Heading 3").Font
.Color = fontRGB 'Change font to Grey
.AllCaps = False 'Remove all caps
.Size = 14 ' sets font size
.Name = "arial" 'sets type of font
End With
With ActiveDocument.Styles("Heading 3").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
ActiveDocument.Styles.Add ("Heading 4")
With ActiveDocument.Styles("Heading 4").Font
.Color = fontRGB 'Change font to Grey
.AllCaps = False 'Remove all caps
.Size = 12 ' sets font size
.Name = "arial" 'sets type of font
End With
With ActiveDocument.Styles("Heading 4").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
' 2010 code to have this working
ListGalleries(wdOutlineNumberGallery).ListTemplates(1).Name = ""
Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
ListGalleries(wdOutlineNumberGallery).ListTemplates(1), _
ContinuePreviousList:=False, ApplyTo:=wdListApplyToWholeList, _
DefaultListBehavior:=wdWord10ListBehavior
' 2003 code to have this working
ListGalleries(wdOutlineNumberGallery).ListTemplates(1).Name = ""
Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
wdOutlineNumberGallery).ListTemplates(5), ContinuePreviousList:=False, _
ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
End Sub
Sub Heading_Style()
With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(1)
.NumberFormat = "%1.0"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.25)
.ResetOnHigher = 0
.StartAt = 1
.LinkedStyle = "Heading 1"
End With
With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(2)
.NumberFormat = "%1.%2"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0.25)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.5)
.ResetOnHigher = 1
.StartAt = 1
.LinkedStyle = "Heading 2"
End With
With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(3)
.NumberFormat = "%1.%2.%3"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0.5)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.75)
.ResetOnHigher = 1
.StartAt = 1
.LinkedStyle = "Heading 3"
End With
With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(4)
.NumberFormat = "%1.%2.%3.%4"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0.75)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(1)
.ResetOnHigher = 1
.StartAt = 1
.LinkedStyle = "Heading 4"
End With
End Sub