Re: Styles help
- From: Russ <drsN0SPAMmikle@xxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 24 Jun 2007 06:02:54 -0400
LEU,
Your other 'procedures' probably have a different pattern when you reveal
the code, right?
The macro is set up to only find the pattern "^dLISTNUM ^#^# \l ^#" that you
were looking for in your original macro that you posted. The MsgBox test
line should not show a blank message, after finding the "^dLISTNUM ^#^# \l
^#" pattern.
I hope you know that it doesn't find any other pattern, but copies of this
macro could be made and altered to find them and then each changed copy
could be ran in succession to find a different pattern. But the heading
style number will probably be in a different part of the pattern and not the
next to the last character or as in this code .Characters.Last.Previous
It is looking for that single number in the pattern that determines the
heading level. If that number is a 0, VBA will complain at the style code
line that there is no Heading 0 in the Heading style collection. There are
only 1-9.
I suppose that if it found a 0, we could have the macro lie and say it was a
1 instead, if that is what you want.
I am not sure what you are saying in your last two messages. Below in your
last message, the code snippet looks like you just added the test line back
into the last version I posted to get it to work, which doesn't quite make
sense. You did use the last version, correct?, and you didn't change the
pattern it was looking for, did you?
Russ,
I got the macro to run if I did the following change to your macro:
MsgBox SearchRange.Characters.Last.Previous 'remove after testing
'Apply Heading Format To Whole Paragraph Using Found Text Number
Selection.Paragraphs(1).Style = ActiveDocument.Styles("Heading " _
& SearchRange.Characters.Last.Previous)
The message box comes up blank and I hit OK. The number is converted and it
goes to the next number and repeats itself all the way down through the
procedure converting the numbers.
LEU
"Russ" wrote:
LEU,
Yes, it was helpful to see what you were doing.
I was originally just adapting to the actions you were doing in the macro
you posted at the start.
I made some adjustments and added comments.
I hope this copies and pastes OK.
I tried to format this code with short lines.
Dim SearchRange As Range
Set SearchRange = ActiveDocument.Range
SearchRange.TextRetrievalMode.IncludeFieldCodes = True
With SearchRange.Find
.Forward = True
.Wrap = wdFindStop
.ClearFormatting
.Format = True
.Text = "^dLISTNUM ^#^# \l ^#"
.Replacement.Text = ""
While .Execute
'Select Found Text
SearchRange.Select
'Apply List Format To Selection
ListGalleries(wdOutlineNumberGallery).ListTemplates(5).Name = ""
Selection.Range.ListFormat.ApplyListTemplate _
ListTemplate:=ListGalleries(wdOutlineNumberGallery _
).ListTemplates(5), ContinuePreviousList:=True, _
ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:=2
'Apply Heading Format To Whole Paragraph Using Found Text Number
Selection.Paragraphs(1).Style = ActiveDocument.Styles("Heading " _
& SearchRange.Characters.Last.Previous)
'Delete Found Text
SearchRange.Text = ""
'Reset Range For Next Search Area
SearchRange.SetRange Start:=SearchRange.End, _
End:=ActiveDocument.Range.End
Wend
End With
Thank you for your help and time that you have spent on this.
I don’t think I am explaining myself very well. This is what my procedure
looks like:
1.0 PURPOSE
To provide instruction for flushing the lube oil system on RFW DT 1B and RFW
P 1B to ensure system cleanliness after overhaul.
2.0 REFERENCES
2.1 CVI 12 00,16, Delaval Manual
2.2 CVI 11A 00,70, Ingersoll Rand Manual
2.3 CVI 12 00,8, Vendor Drawing F 10885 (Unit Oil And Control Diagram)
This is what it looks like when I reveal the codes (Alt+F9):
{LISTNUM 24 \l 1}0 PURPOSE
To provide instruction for flushing the lube oil system on RFW DT 1B and RFW
P 1B to ensure system cleanliness after overhaul.
{LISTNUM 24 \l 1}0 REFERENCES
{LISTNUM 24 \l 2} CVI 12 00,16, Delaval Manual
{LISTNUM 24 \l 2} CVI 11A 00,70, Ingersoll Rand Manual
{LISTNUM 24 \l 2} CVI 12 00,8, Vendor Drawing F 10885 (Unit Oil And Control
Diagram)
This is what it looks like after I run the macro:
Heading 1PURPOSE
To provide instruction for flushing the lube oil system on RFW DT 1B and RFW
P 1B to ensure system cleanliness after overhaul.
Heading 1REFERENCES
Heading 2CVI 12 00,16, Delaval Manual
Heading 2CVI 11A 00,70, Ingersoll Rand Manual
Heading 2CVI 12 00,8, Vendor Drawing F 10885 (Unit Oil And Control Diagram)
Heading 1 should become Style Heading 1
Heading 2 should become Style Heading 2
Heading 3 should become Style Heading 3
I hope that this makes better sense.
LEU
"Russ" wrote:
LEU,
For your information, I recorded a macro while applying a certain style of
number list that I thought you wanted and then looked at that macro and
extracted the lines that I thought were most relevant to add to our ongoing
macro design. I did a short test on a test document and it seemed to work
OK.
LEU,
Your original macro was changing the found pattern to **styles** Heading
1,
Heading 2, etc.
That is what my macro did for you, too.
To also add numbering, try the 'two' lines below, inserted into macro
where
I placed them. That new second line is actually one, long one.
I was working with Russ on this but I had a family emergency and gone forListGalleries(wdOutlineNumberGallery).ListTemplates(5).Name = ""
5
days. I have the following macro but can¹t get it to work right. When I
run
the macro for example it converts "^dLISTNUM 24 \l 2" to the word
"Heading
2". It doesn't see that as an Outline Number style and make it ³1.2².
Dim SearchRange As Range
Set SearchRange = ActiveDocument.Range
SearchRange.TextRetrievalMode.IncludeFieldCodes = True
With SearchRange.Find
.Forward = True
.Wrap = wdFindStop
.ClearFormatting
.Format = True
.Text = "^dLISTNUM ^#^# \l ^#"
.Replacement.Text = ""
While .Execute
SearchRange.Text = "Heading " &
SearchRange.Characters.Last.Previous
SearchRange.Select
Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries(
_
wdOutlineNumberGallery).ListTemplates(5), ContinuePreviousList:=True, _
ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:=2
Selection.Style = ActiveDocument.Styles("Heading " & _
SearchRange.Characters.Last)
SearchRange.SetRange Start:=SearchRange.End, _
End:=ActiveDocument.Range.End
Wend
End With
LEU
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
.
- Follow-Ups:
- Re: Styles help
- From: LEU
- Re: Styles help
- References:
- Re: Styles help
- From: Russ
- Re: Styles help
- From: Russ
- Re: Styles help
- From: LEU
- Re: Styles help
- From: Russ
- Re: Styles help
- From: LEU
- Re: Styles help
- Prev by Date: Re: Styles help
- Next by Date: Re: Bizarre table behaviour - can you explain?
- Previous by thread: Re: Styles help
- Next by thread: Re: Styles help
- Index(es):
Relevant Pages
|