Re: Styles help by LEU
LEU
Sat Jun 23 23:37:03 CDT 2007
Russ,
I tried this macro and it worked on the first procedure but would not work
on the second or third procedure I tried. It gives me the same error that the
requested member of the collection does not exist at the following spot in
the macro:
Selection.Paragraphs(1).Style = ActiveDocument.Styles("Heading " _
& SearchRange.Characters.Last.Previous)
Why it keeps hanging up there I don't know sense it worked great on the
first procedure(Very fast). I feel that I have taken up to much of your time
working on this. My orginal macro works but it just takes time to run. If
your ready to call it quits, thats fine with me.
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 for 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
> >>> ListGalleries(wdOutlineNumberGallery).ListTemplates(5).Name = ""
> >>> 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
> >>>>
> >>>>
> >>>&g