Selection.Find.Execute FindText:=OrigDocID, ReplaceWith:=NewVersio

W

Wes

I'm using this line of code to find a specific section of text (OrigDocID) in
a document and replace it with different text (NewVersion).

Previously lines are:
Selection.HomeKey
Selection.MoveRight unit:=wdSentence, Extend:=wdExtend

The FindText is completely ignored, as if the data wasn't found. Both
OrigDocID and NewVersion are of the format: "9999999v99".

Any questions or ideas?

Thanks,
Wes
 
D

Doug Robbins - Word MVP

You should show us the whole of your code.

To find a number like that, you should use Wildcards with a FindText of

[0-9]{7}v[0-9]{2}

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
W

Wes

I'm looking for a specific value which is stored in the variable OrigDocID.
Pattern matching may pick up other values. This code is used with a document
management system, to update the document footer with a new number when it
assigned.

Here is that section of code:
'OrigDocID and NewVersion are strings

SecCt = ActiveWindow.ActivePane.Document.Sections.Count
For s = 1 To SecCt 'Loop through the sections 1.1
Selection.GoTo what:=wdGoToSection, which:=wdGoToAbsolute, Count:=s
'Move focus to next section
For h = 1 To 3 'three header types
Select Case h '1.1.1
Case 1
ActiveWindow.ActivePane.View.SeekView =
wdSeekFirstPageHeader
'This should insure positioning at top line of footer
ActiveWindow.ActivePane.View.SeekView =
wdSeekFirstPageFooter
Case 2
ActiveWindow.ActivePane.View.SeekView =
wdSeekPrimaryHeader
ActiveWindow.ActivePane.View.SeekView =
wdSeekPrimaryFooter
Case 3
ActiveWindow.ActivePane.View.SeekView =
wdSeekEvenPagesHeader
ActiveWindow.ActivePane.View.SeekView =
wdSeekEvenPagesFooter
End Select 'End 1.1.1
If Err.Number = 5895 Then 'Check if footer type exists '1.1.2
Err.Clear
Else '1.1.2
With Selection '1.1.2.1
Do
.HomeKey
.MoveRight unit:=wdSentence, Extend:=wdExtend
.Find.Execute FindText:=OrigDocID,
ReplaceWith:=NewVersion
.MoveDown
Loop Until Selection.HeaderFooter.IsHeader = True
End With 'End 1.1.2.1
End If
Next h
Next s 'Loop through the sections 1.1
ActiveDocument.Save

Doug Robbins - Word MVP said:
You should show us the whole of your code.

To find a number like that, you should use Wildcards with a FindText of

[0-9]{7}v[0-9]{2}

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Wes said:
I'm using this line of code to find a specific section of text (OrigDocID)
in
a document and replace it with different text (NewVersion).

Previously lines are:
Selection.HomeKey
Selection.MoveRight unit:=wdSentence, Extend:=wdExtend

The FindText is completely ignored, as if the data wasn't found. Both
OrigDocID and NewVersion are of the format: "9999999v99".

Any questions or ideas?

Thanks,
Wes
 
D

Doug Robbins - Word MVP

See the article "Using a macro to replace text where ever it appears in a
document including Headers, Footers, Textboxes, etc." at:

http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Wes said:
I'm looking for a specific value which is stored in the variable
OrigDocID.
Pattern matching may pick up other values. This code is used with a
document
management system, to update the document footer with a new number when it
assigned.

Here is that section of code:
'OrigDocID and NewVersion are strings

SecCt = ActiveWindow.ActivePane.Document.Sections.Count
For s = 1 To SecCt 'Loop through the sections 1.1
Selection.GoTo what:=wdGoToSection, which:=wdGoToAbsolute, Count:=s
'Move focus to next section
For h = 1 To 3 'three header types
Select Case h '1.1.1
Case 1
ActiveWindow.ActivePane.View.SeekView =
wdSeekFirstPageHeader
'This should insure positioning at top line of footer
ActiveWindow.ActivePane.View.SeekView =
wdSeekFirstPageFooter
Case 2
ActiveWindow.ActivePane.View.SeekView =
wdSeekPrimaryHeader
ActiveWindow.ActivePane.View.SeekView =
wdSeekPrimaryFooter
Case 3
ActiveWindow.ActivePane.View.SeekView =
wdSeekEvenPagesHeader
ActiveWindow.ActivePane.View.SeekView =
wdSeekEvenPagesFooter
End Select 'End 1.1.1
If Err.Number = 5895 Then 'Check if footer type exists '1.1.2
Err.Clear
Else '1.1.2
With Selection '1.1.2.1
Do
.HomeKey
.MoveRight unit:=wdSentence, Extend:=wdExtend
.Find.Execute FindText:=OrigDocID,
ReplaceWith:=NewVersion
.MoveDown
Loop Until Selection.HeaderFooter.IsHeader = True
End With 'End 1.1.2.1
End If
Next h
Next s 'Loop through the sections 1.1
ActiveDocument.Save

Doug Robbins - Word MVP said:
You should show us the whole of your code.

To find a number like that, you should use Wildcards with a FindText of

[0-9]{7}v[0-9]{2}

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Wes said:
I'm using this line of code to find a specific section of text
(OrigDocID)
in
a document and replace it with different text (NewVersion).

Previously lines are:
Selection.HomeKey
Selection.MoveRight unit:=wdSentence, Extend:=wdExtend

The FindText is completely ignored, as if the data wasn't found. Both
OrigDocID and NewVersion are of the format: "9999999v99".

Any questions or ideas?

Thanks,
Wes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top