Bonjour,
Dans son message, < Roscoe > écrivait :
In this message, < Roscoe > wrote:
|| I am tired of constantly having to tweak my paragragh numbering
|| because of Word bugs, but this most recent one is killing me. Note I
|| don't use VBA to set my numbering schemes, but at this point it sure
|| sounds attractive to learn how. (most of my VBA skills are from
|| recording macros, examining, and cleaning them up to my purpose).
||
|| I built a document that seems to work OK numbering wise, and all of
|| the styles are uniquely named so as to not be duplicated within
|| another document in which it has to be inserted (merged?).
||
|| My document has two sections. The first section is numbered
|| differently than the second section (Section one has paragraghs L-1,
|| L-2, etc, and the second is M-1, M-2, etc..., both with sunsequent sub
|| paragraghs). It is to be merged into a document where the builder
|| used the normal style primarily, each para manually formatted, with
|| manual numbering. (They used some header stlyes, but only for the
|| formatting, not the numbering). As you can probably tell, their Word
|| skills are rudimentary...not unusual in governement offices.
||
|| When I merge in my document, the first section works OK (L-1 etc), but
|| the second drops all of the numbering, but appears to leaves the
|| styles otherwise OK. When I try to reapply the numbering to the
|| second section, some of the stlyes change and messes averything up. I
|| can fix it with time and patience, but the person who will be doing
|| the actual merging doesn't have the skill (ps. I told them NOT to
|| merge as it willl be distributed in printed form anyway, but they
|| insist as it is "policy"). Not to mention that this is a document
|| that will be edited frequently and then reinserted each time (truly a
|| pain because the first insertion also insert the styles which stay and
|| overide any changes I may make in my document...arrrggghhh)
||
|| I am lost at this point. Minor edits are becoming way too much work.
|| I am beginning to think that the best way would be to build a VBA
|| routine that resets the numbering gallery and rebuilds it with the two
|| schemes I use, but my VBA skills are very rusty and I quite frankly
|| don't have the time to relearn them from scratch. If someone has a
|| routine built that I can edit with the parameters (number, indents,
|| etc...) I would be ETERNALLY GRATEFUL.
Here is a macro I have used. You will have to adjust it to your
requirements. Here is the background for this macro:
I needed templates that would generates documents that would end up being
pasted together in one long document to produce training manuals. There were
dozens of authors and 6 different templates.
I needed only one level of numbering, but I did not want the numbering to
get messed up after the pasting; especially the list numbering starting
points. If an author set the numbering to start at one, it had to stay at
one after the pasting.
Since all styles would have the same names, I had to find a way to enforce
this.
I used the Hidden level technique.
This macro builds a base style on which all other styles are based (to avoid
being based on Normal, but the base itself is based on Normal). Then it
builds the hidden level (Numbered Style Level 0) and the first level
(Numbered Style). Finally, it build a list template and associate the level
0 to the first level and the Numbered Style to level 1. Notice that all
indentation and tabs for positioning the numbers in the numbered styles is
dealt with in the list template definitions, not in the style definition.
To start numbering in the document, apply level 0 then hit Enter to get
Level 1. Whenever a list has to restart at one, just precede the first
numbered paragraph by a level 0 paragraph.
This macro was designed to run in a template, so it deletes all instances of
the styles having the same name. If you run it in a document, it will remove
all formatting form pre-existing paragraphs that were formatted with these
styles. If you want to run it in a document that already uses these styles,
you will have to comment out these lines:
'_______________________________________
StyleFound = False
For Each oStyle In ActiveDocument.Styles
If ActiveDocument.Styles(oStyle) = StyleNameBase Then
StyleFound = True
oStyle.Delete
Exit For
End If
Next oStyle
'_______________________________________
and
'_______________________________________
ActiveDocument.Styles.Add Name:=StyleNameBase, _
Type:=wdStyleTypeParagraph
'_______________________________________
(Three times, Base, Level 0 and Numbered styles)
Also, if you do not want the Level 0 thingy, remove all the code that deals
with its creation and assign Numbered Style as the first level in the List
template section of the macro.
Finally, if you need many levels of numbering,
Add a constant at the top to name the style,
e.g. Const StyleName As String = "Numbered Style Level 1"
Take the Numbered Style block and paste it,
Change the style definition and constant name,
Add a level in the List template block by copying and pasting one of the
level (and just adjust the pasted text).
'_______________________________________
Sub CreateStyle()
Dim oLstTemplate As ListTemplate, TemplateFound As Boolean
Dim oStyle As Style, StyleFound As Boolean
Const StyleNameBase As String = "Numbered Style Base"
Const Style0Name As String = "Numbered Style Level 0"
Const StyleName As String = "Numbered Style"
Const ListTemplateName As String = "MyListTemplate"
'------------------------------------------------------------
'------------------------------------------------------------
'BASE STYLE
'-------------------------------------------------
'Delete style if it already exists
StyleFound = False
For Each oStyle In ActiveDocument.Styles
If ActiveDocument.Styles(oStyle) = StyleNameBase Then
StyleFound = True
oStyle.Delete
Exit For
End If
Next oStyle
'------------------------------------------------
'Then create the base style
ActiveDocument.Styles.Add Name:=StyleNameBase, _
Type:=wdStyleTypeParagraph
Set oStyle = ActiveDocument.Styles(StyleNameBase)
'-------------------------------------------------
'and adjust it to taste
With oStyle
.AutomaticallyUpdate = False
.BaseStyle = "Normal"
With .ParagraphFormat
.SpaceAfter = 6
End With
End With
'------------------------------------------------------------
'------------------------------------------------------------
'------------------------------------------------------------
'------------------------------------------------------------
'NUMBERED STYLE
'-------------------------------------------------
'Delete style if it already exists
StyleFound = False
For Each oStyle In ActiveDocument.Styles
If ActiveDocument.Styles(oStyle) = StyleName Then
StyleFound = True
oStyle.Delete
Exit For
End If
Next oStyle
'-------------------------------------------------
'Then create the numbered style
ActiveDocument.Styles.Add Name:=StyleName, _
Type:=wdStyleTypeParagraph
Set oStyle = ActiveDocument.Styles(StyleName)
'-------------------------------------------------
'and adjust it to taste
With oStyle
.AutomaticallyUpdate = False
.BaseStyle = StyleNameBase
With .ParagraphFormat
.SpaceAfter = 3
.SpaceBefore = 3
End With
End With
'------------------------------------------------------------
'------------------------------------------------------------
'------------------------------------------------------------
'------------------------------------------------------------
'LEVEL 0 STYLE
'-------------------------------------------------
'Delete style if it already exists
StyleFound = False
For Each oStyle In ActiveDocument.Styles
If ActiveDocument.Styles(oStyle) = Style0Name Then
StyleFound = True
oStyle.Delete
Exit For
End If
Next oStyle
'-------------------------------------------------
'Then create the level 0 style
ActiveDocument.Styles.Add Name:=Style0Name, _
Type:=wdStyleTypeParagraph
Set oStyle = ActiveDocument.Styles(Style0Name)
'-------------------------------------------------
'and adjust it to taste
With oStyle
.AutomaticallyUpdate = False
.BaseStyle = "Normal"
.NextParagraphStyle = StyleName
With .ParagraphFormat
.SpaceAfter = 0
.SpaceBefore = 0
.KeepWithNext = True
.LineSpacingRule = wdLineSpaceSingle
End With
.Font.Size = 1
.Font.Color = wdColorWhite
End With
'------------------------------------------------------------
'------------------------------------------------------------
'------------------------------------------------------------
'------------------------------------------------------------
'LIST TEMPLATE
'-------------------------------------------------
'Find or create the list template
For Each oLstTemplate In ActiveDocument.ListTemplates
If oLstTemplate.Name = ListTemplateName Then
TemplateFound = True
Exit For
End If
Next oLstTemplate
'-------------------------------------------------
If TemplateFound Then
Set oLstTemplate = ActiveDocument _
.ListTemplates(ListTemplateName)
Else
Set oLstTemplate = ActiveDocument _
.ListTemplates.Add(OutlineNumbered:=True)
oLstTemplate.Name = ListTemplateName
End If
'-------------------------------------------------
'and adjust the list template
With oLstTemplate.ListLevels(1)
.NumberFormat = ""
.TrailingCharacter = wdTrailingNone
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.33)
.TabPosition = wdUndefined
.ResetOnHigher = True
.StartAt = 1
.LinkedStyle = Style0Name
End With
'-------------------------------------------------
With oLstTemplate.ListLevels(2)
.NumberFormat = "%2."
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.16)
.TabPosition = wdUndefined
.ResetOnHigher = True
.StartAt = 1
.LinkedStyle = StyleName
End With
'------------------------------------------------------------
'------------------------------------------------------------
End Sub
'_______________________________________
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org