Hi Hari,
have a look at this one:
There may be complications,
if the text to add would not fit on the page,
that is currently processed. Unlikely, though.
And, it is assumed, that we are not talking about
headers or footers, but about "page xx" in the main story.
Sub Secondtry()
ResetSearch
Dim lPgs As Long
Dim lTmp As Long
lPgs = Selection.Information(wdNumberOfPagesInDocument)
For lTmp = 1 To lPgs
Selection.GoTo _
what:=wdGoToPage, _
which:=wdGoToAbsolute, _
Count:=lTmp
Selection.Bookmarks("\page").Select
With Selection.Find
.Text = "page [0-9]{1,2}"
.Replacement.Text = "page " & lTmp & " - 31"
.Wrap = wdFindStop
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Next
ResetSearch
End Sub
'---
Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' plus some more
.Execute
End With
End Sub
There may be other and faster ways, which may have
to be considered, if necessary, once you have a working
solution.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Hari Prasadh - 28 Jan 2005 12:46 GMT
Hi Helmut,
Dont know how to express you my Immense Gratitude. Not because the macro is
working perfectly (it works like a CHARM), BUT more so, you have taught me
that what is typed by a user on a word document is referred to as MAIN
STORY. Since, I didnt know that I couldnt express my requirement properly in
my earlier post to another word group. For many this might be a very basic
stuff, but because of limiting myself to using Word as a Scratch
application, this has been a revelation.
One minor change I made to your macro -- .Replacement.Text = "Page " &
lTmp - 31 --
(Actually am generating page numbers in the Main Story itself and all this
is being done using some other application. That application's ouput is then
opened in word format. Im not and dont want to use Word's inbuilt Header and
Footer feature).
Thanks a lot,
Hari
India
> Hi Hari,
> have a look at this one:
[quoted text clipped - 56 lines]
> Word XP, Win 98
> http://word.mvps.org/
Helmut Weber - 28 Jan 2005 14:27 GMT
Hi Hari,
Helping makes at least two people feel better.
Have a nive day!
Roger, end and over, see you next time.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/