View Single Post
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Doug Robbins - Word MVP
 
Posts: n/a
Default Using find and replace or macros to replace page ranges

The following macro deals with the case that you mention:

Dim numrange As Range, numrange1 As Range, numrange2 As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{1,}-[0-9]{1,}", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set numrange = Selection.Range
Selection.Range.Collapse wdCollapseEnd
Set numrange1 = numrange.Duplicate
Set numrange2 = numrange.Duplicate
numrange1.End = numrange1.Start + InStr(numrange1, "-") - 1
numrange2.Start = numrange2.Start + InStr(numrange2, "-")
If Len(numrange1) = Len(numrange2) Then
If Left(numrange1, 1) = Left(numrange2, 1) Then
If Mid(numrange1, 2, 1) = Mid(numrange2, 2, 1) Then
numrange = numrange1 & "-" & Mid(numrange2, 3)
Else
numrange = numrange1 & "-" & Mid(numrange2, 2)
End If
End If
End If
Loop
End With


--
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

"JeremyC" wrote in message
...
I am using Word 2003, but if I can successfully figure out how to do this,
I
would also like to be able to do the same on Word 2004 for Mac.

I am trying to figure out a way to automate replacing numbers in page
ranges
to match the Chicago Manual of Style. For instance, I need to change
149-167
to 149-67, but not 149-249 to 149-49 or not 106-108 to 106-08 (instead
that
should go to 106-8). I'm not sure I have thought out all the exceptions,
though these are the most basic. I am mainly looking for the methodology
to
use, whether through find and replace or macros. I don't want to spend too
much time trying to figure it out, because I'm not sure the return will be
worth a lot of time invested.

I know that by using wildcard search and replace I can do most of this.
For
instance, I could search for
([!0-9])([0-9])([0-9])([0-9])-([0-9])([0-9])([0-9]) and replace with
\1\2\3\4\-\5\6, replacing something like " 125-126" to "125-26." But that
doesn't help me with all because I would still have to make adjustments
for
the above-mentioned exceptions.

If automating using macros is the best choice, I would also like to figure
out a way to double-check that changes were made correctly and there were
no
mistakes. So is it possible to write into the macro (if doing a macro) to
copy all replacements (or all things being replaced) into a blank word
document to be able to quickly scan all instances of replacements? Or to
highlight all changes made in the document to be able to quickly pick up
what
was changed?

Does this make sense? Can anyone help? Thanks.