Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing a defined number of characters

Status
Not open for further replies.

DellHater

Programmer
Nov 24, 2006
75
CZ
Hi I am running a few macros in word and one of the manual edits I am looking to turn into vb is the following.

out reports have

PAGE : 101

i need to turn this into PAGExxNOx:xxxxxxx1

where x is a space.
how can i find PAGE and then also look for the rest of the line to capture the actual page number ?
the otehr bit is fine, just curious if there is a way to capture the actual page number following the word 'PAGE :'

thx
 
Whats between the : and the 101. Is this spaces, a TAB or what?

Regular expressions are your best bet I think. Lets say for examples that the expression between your Page: and the number is one or more spaces. The following code should print out the number following the Page:

Dim regEx, Match, Matches

Set regEx = New RegExp ' Create a regular expression.regEx.Pattern = "Page: *(\d+)" ' Set pattern.
regEx.IgnoreCase = False ' Set case insensitivity.
regEx.Global = True ' Set global applicability.

Set Matches = regEx.Execute(ActiveDocument.Range.Text) ' Execute search.
For i = 0 To Matches.Count
For x = 0 To Matches(i).SubMatches.Count
MsgBox Matches(i).SubMatches(x)
Next x
Next i



In order to understand recursion, you must first understand recursion.
 
Here's an example of a relevant field code to achieve the output that you want. You are using field codes, aren't you...

{PAGE \#"PAGE NO : #" \*MERGEFORMAT}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top