N
NavyPsych
Okay, I'm very new at this and this is probably very easy, but here
goes. All I want to do is go into my footer, which contains a few
lines, e.g. NAME: Doe, John, then SSN:....you get the picture. So I
found this subroutine that does that works perfectly (selects name and
bookmarks it), but when I repeat the subroutine to grab and bookmark
the SSN, it doesn't work - the it makes the end of my NAME book mark
turn from an end bracket to the bookmark that looks like a big "I"
So, I experiemented at made rgn2 look for the last number in the
social, e.g. "8" instead of a paragraph marker, and it works (but it
of course doesn't select the "8"
So, my dirty fix is to add a $ to the end to the SSN line, then have
it find that (b/c it's before the ^p), and it grabs the whole social.
Anyway, I don't like having to cheat...I'd like to know why this won't
work. My theory is that it's finding the paragraph marker from the
first line again, but I don't know how to have it find the ^p on the
second line instead. Help!
Sub SelectText()
'Grab NAME
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.WholeStory
Set rng1 = Selection.Range
Set rng2 = rng1.Duplicate
With rng1.Find
.ClearFormatting
.Text = "Name:^w"
.Execute
If .Found Then
With rng2.Find
.Text = "^p"
.Execute
If .Found Then
rng1.Collapse wdCollapseEnd
rng1.End = rng2.Start
rng1.Select
End If
End With
End If
End With
'Add Bookmark
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="NAME"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
'
goes. All I want to do is go into my footer, which contains a few
lines, e.g. NAME: Doe, John, then SSN:....you get the picture. So I
found this subroutine that does that works perfectly (selects name and
bookmarks it), but when I repeat the subroutine to grab and bookmark
the SSN, it doesn't work - the it makes the end of my NAME book mark
turn from an end bracket to the bookmark that looks like a big "I"
So, I experiemented at made rgn2 look for the last number in the
social, e.g. "8" instead of a paragraph marker, and it works (but it
of course doesn't select the "8"
So, my dirty fix is to add a $ to the end to the SSN line, then have
it find that (b/c it's before the ^p), and it grabs the whole social.
Anyway, I don't like having to cheat...I'd like to know why this won't
work. My theory is that it's finding the paragraph marker from the
first line again, but I don't know how to have it find the ^p on the
second line instead. Help!
Sub SelectText()
'Grab NAME
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.WholeStory
Set rng1 = Selection.Range
Set rng2 = rng1.Duplicate
With rng1.Find
.ClearFormatting
.Text = "Name:^w"
.Execute
If .Found Then
With rng2.Find
.Text = "^p"
.Execute
If .Found Then
rng1.Collapse wdCollapseEnd
rng1.End = rng2.Start
rng1.Select
End If
End With
End If
End With
'Add Bookmark
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="NAME"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
'