J.I.B. was telling us:
J.I.B. nous racontait que :
I have tried using the sequence field described. The problem is that
this field needs to be inserted (copied and pasted) manually before
each paragraph. I have not discovered a way of automating this for
specific styles.
Additionally, there are some subheaders which occur throughout the
document which should not be numbered. Fore example:
Title
[0001] text
[0002] text
Header
[0003] text]
Here is what you can do:
1)
Create the SEQ field, add a tab right after this field, select only the
field and the tab (not the ¶ or any other character)
2)
Create an AutoText based on the selection and call it "Num" (Of course, use
whatever name you want): Insert > AutoText... > AutoText > (give the name) >
OK.
3)
Create a style with the parameters you want (Tab or hanging indent at 0.7",
font, space before/after, etc.) Call this style the same name as the
AutoText, "Num" in this example.
4)
Do Alt-F11 to get to the VBA editor.
In the Normal Project, add a module (Right click the Normal Project heading
in the project pane on the left - View > Project Explorer if you cannot see
it) and choose "Module". Then in the code pane on the right for this module,
paste the following code:
'_______________________________________
Option Explicit
Private Const strStyle As String = "Num"
'_______________________________________
Sub ApplyNum()
Dim rgePara As Range
Set rgePara = Selection.Range.Paragraphs(1).Range
With rgePara
If .Style = "Num" Then
MsgBox "The current paragraph style is already """ _
& strStyle & """.", vbExclamation, "Cancelled"
Exit Sub
End If
.Collapse wdCollapseStart
.Style = strStyle
.InsertAfter strStyle
.InsertAutoText
.Fields(1).Result.Font.Bold = True
.Collapse wdCollapseEnd
.Select
End With
End Sub
'_______________________________________
'_______________________________________
Sub RemoveNum()
Dim rgePara As Range
Set rgePara = Selection.Range.Paragraphs(1).Range
With rgePara
If .Style <> strStyle Then
MsgBox "The current paragraph style is not """ _
& strStyle & """.", vbExclamation, "Cancelled"
Exit Sub
End If
.Fields(1).Result.Delete
.Characters(1).Delete
.Style = "Normal"
End With
End Sub
'_______________________________________
5) Close the VBA Editor Window
6) Tools > Customize > Commands tab > Keyboard... button
7) In the category on the left, select "Macros"
8) IN the list on the Right, select ApplyNum
9) Click inside the "Press shortcut key:" area
10) On the keyboard, do "CTRL-1"
11) Click on the "Assign" button (Of course, use whatever shortcut key
combination)
12) IN the list on the Right, select RemoveNum
13) Click inside the "Press shortcut key:" area
14) On the keyboard, do "SHIFT-CTRL-1"
15) Click on the "Assign" button (This is why I used CTRL-1, so that I can
now do SHIFT-CTRL-! to undo, but you could use CTRL-2 here. Of course, if
you already use CTRL-1 for its default shortcut, find another key
assignment)
16) Click on "Close" twice
Now all you have to do is CTRL-1 to apply the style, or SHIFT-CTRL-1 to
"un-apply" it.
If you don't like keyboard shortcuts, you can create toolbar buttons
instead.
Of course, if you have more than one document using this, you may want to
create a template and store all the customization in that template instead
of using Normal
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org