There's more on the web page, but here are the essential steps (thanks
to MVP Graham Mayor):
1. Select Tools > Macro > Macros, and type the macroname into the
Macro name window at the top of the wizard -- i.e. the bit after Sub
and before () .
2. In the panel directly beneath the large macro names window, pick
which template or document you wish the macro to be saved in. If you
select 'All active templates and documents' the macro will be saved
in normal.dot.
3. Click 'Create'.
4. The macro editor will open at the correct place. There will be an
entry as follows:
Sub macroname()
'
' macroname Macro
' Macro created date by user
'
End Sub
5. Copy the complete block of code from the newsgroup message to the
clipboard.
6. Switch to the macro editor window. Select all the above listed
block and paste the contents of the clipboard over it.
7. Click the 'Save' icon and close the editor.
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
On Mon, 15 May 2006 11:54:01 -0700, Fuzzhead
Jay,
My firewall at work will not let me get out to that web sit. I'll have to
wait until I get home tonight and take a look at it to see how to install
your macro into my macro. If I have questions I'll post it tomorrow, unless
you can explain it to me here.
Larry
:
OK, you convinced me. Here's a macro to handle the logic. I did throw
in one thing that contradicts something I said before: The setting of
TextRetrievalMode.IncludeFieldCodes means that the field codes don't
have to be displayed first.
If you need instructions for installing the macro, see
http://www.gmayor.com/installing_macro.htm.
If you want me to tweak its behavior, let me know.
Sub RestyleListnum2()
Dim listnumRange As Range
Dim head1Range As Range
Set listnumRange = ActiveDocument.Range
listnumRange.TextRetrievalMode.IncludeFieldCodes = True
listnumRange.Find.ClearFormatting
listnumRange.Find.Text = "listnum ^#^# \l 2"
Do While listnumRange.Find.Execute
Set head1Range = listnumRange.Duplicate
head1Range.Collapse wdCollapseStart
With head1Range.Find
.Text = ""
.Format = True
.Style = ActiveDocument.Styles("Heading 1")
.Forward = False ' search up
If .Execute Then
If head1Range.ListFormat.ListValue < 4 Then
listnumRange.Style = _
ActiveDocument.Styles("Heading 2")
Else ' it's 4 or more
listnumRange.Style = _
ActiveDocument.Styles("Heading 4")
End If
Else ' there is no preceding Heading 1
listnumRange.Style = _
ActiveDocument.Styles("Heading 2")
End If
End With
Loop
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
On Mon, 15 May 2006 10:33:02 -0700, Fuzzhead
Jay,
Unfortunately we have a large number of documents to do. We are converting
years of WordPerfect Docs over to Word. I would love not to have to go back
in to each doc and correct the headings. The reason we need to use 2
different Headings on “LISTNUM XX \l 2†is to setup the margins. When Heading
1 equals 1.0, 2.0 or 3.0 then LISTNUM XX \l 2 under those Heading 1s needs to
equal Heading 2 and when Heading 1 equals 4.0 then LISTNUM XX \l 2 under
Heading 1 needs to equals Heading 4.
:
To make a decision like that, you have to do the Find/Replace in a
macro. For each Listnum \l 2 it finds, it needs to examine the value
of the most recent Heading 1 and decide which style to apply. This is
nontrivial programming, and it's worth doing only if there are many
headings that would need manual intervention, or if you need to
process many documents.
Personally, I wouldn't have let the document get into its current
state in the first place. ;-)
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
On Mon, 15 May 2006 06:19:03 -0700, Fuzzhead
Jay,
I was out of the office for a few days. THank you for your help. I tried it
first thing this morning and It worked great.
I have one other question about numbering. Once I change my Listnum XX \l 1
to Heading 1 can you do the following?
If Heading 1 is less than 4.0 use Heading 2 on Listnum \l 2 else Listnum \l
2 equals Heading 4.
Or do I have to pick one or the other and go back and manually change the
ones that are wrong?
Again thanks for all your help.
Larry
:
OK, I was thrown off by your first post having \l 1 in all the examples. But
you still don't need wildcards if the XX in all the fields really are two
digits. To change all the level-1 listnums to Heading 1 style, use the
search expression
^d LISTNUM ^#^# \l 1
and the replace expression
^&
with the Heading 1 style chosen (I assume you know how to use the More and
Format buttons in the dialog to set that). Then click Replace All. Repeat
with \l 2 and Heading 2; \l 3 and Heading 3.
If the XX might be either one digit or two, then you have a choice: You can
do two replacements for each level, one with a single ^# and one with ^#^#;
or you can do one wildcard replacement with the search expression
LISTNUM [0-9]{1,2} \\l 1
(notice that for a wildcard search you have to use two backslashes to match
one backslash).
In either case, you have to have field codes displayed.
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
Fuzzhead wrote:
I guess I did not explain myself very well. I am tying LISTNUM'S to
Headings. So I have LISTNUM 40 \l 1, LISTNUM 40 \l 2 and LISTNUM 40
\l 3 or the 40's could be 39, 41 or 29 as examples. The "LISTNUM XX
\l 1" are being replaced by Heading 1. The "LISTNUM XX \l 2" are
being replaced by Heading 2 and "LISTNUM XX \l 3" are being replaced
by Heading 3. I want to write a macro that would only look at the "\l
1" or the "\l 2" in the LISTNUM and based on it would replace it with
Heading 1, 2 or 3. Can this be done?
:
You don't need a wildcard. First press Alt+F9 so all the field codes
are visible. Then use the following search expression:
^d LISTNUM
(note the space after the d). That will find any LISTNUM field.
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
On Thu, 11 May 2006 15:03:01 -0700, Fuzzhead
Can you insert wildcards inside of a LISTNUM to find all the
different styles in the document? Examples are as follows:
{LISTNUM 23 \l 1}
{LISTNUM 40 \l 1}
{LISTNUM 41 \l 1}