Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
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} |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
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 FAQ: http://word.mvps.org 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 wrote: 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} |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
I guess I did not explain myself very well. I am tying LISTNUMS to Headings.
So I have LISTNUM 40 \l 1, LISTNUM 40 \l 2 and LISTNUM 40 \l 3 or the 40s 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? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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} |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
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 FAQ: http://word.mvps.org 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? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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} |
#5
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
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 "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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} |
#6
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
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 FAQ: http://word.mvps.org 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 wrote: 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 "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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} |
#7
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
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. "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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 "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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} |
#8
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
OK, you convinced me. Here's a macro to handle the logic. I did throw
in one thing that contradicts something I said befo 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 FAQ: http://word.mvps.org 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 wrote: 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. "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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 "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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} |
#9
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
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 "Jay Freedman" wrote: OK, you convinced me. Here's a macro to handle the logic. I did throw in one thing that contradicts something I said befo 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 FAQ: http://word.mvps.org 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 wrote: 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. "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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 "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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} |
#10
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
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 FAQ: http://word.mvps.org 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 wrote: 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 "Jay Freedman" wrote: OK, you convinced me. Here's a macro to handle the logic. I did throw in one thing that contradicts something I said befo 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 FAQ: http://word.mvps.org 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 wrote: 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. "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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 "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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} |
#11
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
Jay,
I loaded the macro and ran it; but nothing happened. My heading 1 looks as follows: 1.0 text 2.0 test 3.0 text 4.0 text I saw in your macro you refer to the following: "If head1Range.ListFormat.ListValue 4 Then " Is the reason it didn't work is you say 4 but my heading is 4.0? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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 "Jay Freedman" wrote: OK, you convinced me. Here's a macro to handle the logic. I did throw in one thing that contradicts something I said befo 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 FAQ: http://word.mvps.org 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 wrote: 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. "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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 "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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} |
#12
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
Hmm, I wondered about that 4.0. I should have realized that, coming
from WordPerfect, the document wouldn't have automatic heading numbers. That's what the macro looks for (the ListFormat.ListValue). In the actual document, are the heading numbers just ordinary typed text? No fields, no automatic numbering? If that's what it is, I think the change needed in the macro is to replace the line you quoted with If Val(Left(head1Range.Text, 3)) 4 Then What this does is take the first three characters of the Heading 1 text (assuming any Heading 1 is found earlier in the document than the Listnum), try to translate those three characters to a number (which might be, say, 3.0 or 2.8), and ask whether the value of that number is less than 4. You should understand that the macro assumes you've already used the Replace we discussed earlier to change the Listnum \l 1 entries to have Heading 1 style. On Mon, 15 May 2006 14:36:01 -0700, Fuzzhead wrote: Jay, I loaded the macro and ran it; but nothing happened. My heading 1 looks as follows: 1.0 text 2.0 test 3.0 text 4.0 text I saw in your macro you refer to the following: "If head1Range.ListFormat.ListValue 4 Then " Is the reason it didn't work is you say 4 but my heading is 4.0? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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 "Jay Freedman" wrote: OK, you convinced me. Here's a macro to handle the logic. I did throw in one thing that contradicts something I said befo 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 FAQ: http://word.mvps.org 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 wrote: 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. "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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 "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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} -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
#13
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
Jay,
The 1.0, 2.0, 3.0 & 4.0 in heading 1 are outline numbers created by word. I tried your change anyway but nothing happened using it either. I also changed the following line from listnumRange.Find.Text = "listnum ^#^# \l 2" to listnumRange.Find.Text = "^dlistnum ^#^# \l 2" but that made no difference also. Larry "Jay Freedman" wrote: Hmm, I wondered about that 4.0. I should have realized that, coming from WordPerfect, the document wouldn't have automatic heading numbers. That's what the macro looks for (the ListFormat.ListValue). In the actual document, are the heading numbers just ordinary typed text? No fields, no automatic numbering? If that's what it is, I think the change needed in the macro is to replace the line you quoted with If Val(Left(head1Range.Text, 3)) 4 Then What this does is take the first three characters of the Heading 1 text (assuming any Heading 1 is found earlier in the document than the Listnum), try to translate those three characters to a number (which might be, say, 3.0 or 2.8), and ask whether the value of that number is less than 4. You should understand that the macro assumes you've already used the Replace we discussed earlier to change the Listnum \l 1 entries to have Heading 1 style. On Mon, 15 May 2006 14:36:01 -0700, Fuzzhead wrote: Jay, I loaded the macro and ran it; but nothing happened. My heading 1 looks as follows: 1.0 text 2.0 test 3.0 text 4.0 text I saw in your macro you refer to the following: "If head1Range.ListFormat.ListValue 4 Then " Is the reason it didn't work is you say 4 but my heading is 4.0? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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 "Jay Freedman" wrote: OK, you convinced me. Here's a macro to handle the logic. I did throw in one thing that contradicts something I said befo 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 FAQ: http://word.mvps.org 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 wrote: 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. "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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 "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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? "Jay Freedman" wrote: 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 FAQ: http://word.mvps.org 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 wrote: 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} -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
#14
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
Hi Larry,
Would you be willing to send me a copy of the document, or at least a piece of it, so I can tinker with the macro? I'm sure it's solvable, but not by long-distance description. The email address in the header is valid. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Fuzzhead wrote: Jay, The 1.0, 2.0, 3.0 & 4.0 in heading 1 are outline numbers created by word. I tried your change anyway but nothing happened using it either. I also changed the following line from listnumRange.Find.Text = "listnum ^#^# \l 2" to listnumRange.Find.Text = "^dlistnum ^#^# \l 2" but that made no difference also. Larry "Jay Freedman" wrote: Hmm, I wondered about that 4.0. I should have realized that, coming from WordPerfect, the document wouldn't have automatic heading numbers. That's what the macro looks for (the ListFormat.ListValue). In the actual document, are the heading numbers just ordinary typed text? No fields, no automatic numbering? If that's what it is, I think the change needed in the macro is to replace the line you quoted with If Val(Left(head1Range.Text, 3)) 4 Then What this does is take the first three characters of the Heading 1 text (assuming any Heading 1 is found earlier in the document than the Listnum), try to translate those three characters to a number (which might be, say, 3.0 or 2.8), and ask whether the value of that number is less than 4. You should understand that the macro assumes you've already used the Replace we discussed earlier to change the Listnum \l 1 entries to have Heading 1 style. On Mon, 15 May 2006 14:36:01 -0700, Fuzzhead wrote: Jay, I loaded the macro and ran it; but nothing happened. My heading 1 looks as follows: 1.0 text 2.0 test 3.0 text 4.0 text I saw in your macro you refer to the following: "If head1Range.ListFormat.ListValue 4 Then " Is the reason it didn't work is you say 4 but my heading is 4.0? |
#15
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
LISTNUM & Wildcards
Jay,
I emailed you a copy. Larry "Jay Freedman" wrote: Hi Larry, Would you be willing to send me a copy of the document, or at least a piece of it, so I can tinker with the macro? I'm sure it's solvable, but not by long-distance description. The email address in the header is valid. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Fuzzhead wrote: Jay, The 1.0, 2.0, 3.0 & 4.0 in heading 1 are outline numbers created by word. I tried your change anyway but nothing happened using it either. I also changed the following line from listnumRange.Find.Text = "listnum ^#^# \l 2" to listnumRange.Find.Text = "^dlistnum ^#^# \l 2" but that made no difference also. Larry "Jay Freedman" wrote: Hmm, I wondered about that 4.0. I should have realized that, coming from WordPerfect, the document wouldn't have automatic heading numbers. That's what the macro looks for (the ListFormat.ListValue). In the actual document, are the heading numbers just ordinary typed text? No fields, no automatic numbering? If that's what it is, I think the change needed in the macro is to replace the line you quoted with If Val(Left(head1Range.Text, 3)) 4 Then What this does is take the first three characters of the Heading 1 text (assuming any Heading 1 is found earlier in the document than the Listnum), try to translate those three characters to a number (which might be, say, 3.0 or 2.8), and ask whether the value of that number is less than 4. You should understand that the macro assumes you've already used the Replace we discussed earlier to change the Listnum \l 1 entries to have Heading 1 style. On Mon, 15 May 2006 14:36:01 -0700, Fuzzhead wrote: Jay, I loaded the macro and ran it; but nothing happened. My heading 1 looks as follows: 1.0 text 2.0 test 3.0 text 4.0 text I saw in your macro you refer to the following: "If head1Range.ListFormat.ListValue 4 Then " Is the reason it didn't work is you say 4 but my heading is 4.0? |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
listnum converting | Microsoft Word Help | |||
Formatting Listnum field | Microsoft Word Help | |||
Restart numbering using LISTNUM | Microsoft Word Help | |||
StyleRef, Character Styles and ListNum | Page Layout | |||
Wildcards using [ ] characters | Microsoft Word Help |