Thread: [Solved] Save Selection
View Single Post
 
Old 01-14-2011, 06:39 PM
cksm4 cksm4 is offline Windows XP Office 2007
Advanced Beginner
 
Join Date: Aug 2010
Posts: 48
cksm4 is on a distinguished road
Default

Hey Paul,

Quote:
What are you trying to loop - the Sections or adding to the 'IndexThis' bookmark


Each document will always have the wording "Category 1" near the top of the document. Since I will be combining the documents into one document prior to running the below code, I decided not to use a bookmark to place the index. I just have the code go the next row after the last category is found and paste the index there. This next row is blank and can be used for this.

Code:
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Category 1"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
vCatagory1 = Selection.Text
Selection.Collapse
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Category 2:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCell
vCatagory2 = Selection.Text
Selection.Collapse
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Category 3"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCell
vCatagory3 = Selection.Text
Selection.MoveRight Unit:=wdCell
ActiveDocument.Indexes.MarkEntryRange:=Selection.Range, _
Entry:=vCatagory1 & ":" & vCatagory2 & ":" & vCatagory3, CrossReference:="", CrossReferenceAutoText:="", _
BookmarkName:="", Bold:=False, Italic:=False


I would be nice to also limit the code to sections so that if somehow it found "Category 1" and not "Category 2" it does not go to the next section (another form) looking for "Category 2". Just me being cautious!

Quote:
From what you've described so far, Find/Replace is not a good way to approach this IMHO.


I can use code to find ContentControl(1) because I will be combining multiple of these forms into one document prior to running this code. It is my understanding then that after I do this, the code will only find one ContentControl(1)... the one on the last form. The ones on all the rest of the forms will rename.

Thanks again Paul!
Reply With Quote