Find/Replace with sequential number

C

Carol

Hi, I'm figuring this is probably an easy thing to do...for someone who
has a clue. Unfortunately, I don't.

What I'd like to do (and I'm using a Mac/Word2004) is this:

find 12:00:00 and change it to 12:01:00 (or 12:00:01, doesn't matter)
and then the next instance 12:00:02 and so on through 59.

Is this possible using MS Word? (I also have Virtual PC, which lets me
emulate WIndows apps, and tried a piece of shareware I found online, but
never could get it to work right) I don't know how macros and VBA works;
have never used it or figured it out. ::shrug::

What I'm doing is importing flat text files into a WordPress database,
and one of the fields is date/time. I've got thousands of files, and
each time field needs to be a second off the next for this to work right.

Thank you. :)
 
G

Greg Maxey

Something like:
Sub FRWithSequentialNumber()
Dim startNum As String
Dim myRange As Range
Set myRange = ActiveDocument.Range
startNum = "01"
With myRange.Find
.Text = "12:00:00"
.MatchWholeWord = True
While .Execute
myRange.Text = "12:" & Format(startNum, "00:00")
If startNum = "59" Then
startNum = "01"
Else
startNum = startNum + 1
End If
myRange.Collapse Direction:=wdCollapseEnd
Wend
End With
End Sub
 
D

Doug Robbins - Word MVP

The following will do it on a Windows machine; no guarantee about a Mac

Dim i As Long, myrange As Range
i = 1
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{2}:[0-9]{2}:[0-9]{2}", _
MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Selection.MoveRight wdCharacter, 1
myrange.Text = Left(myrange.Text, 6) & Format(i, "0#")
i = i + 1
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
 
C

Carol

Unbelievable...this worked like a charm!!!

I can't thank you enough.

Greg, I tried yours, but got some kind of error. However, know that I
probably did something wrong, because I really had no idea what I was
doing.

Thanks again so very much, both of you. I'm so stunned this
worked...LOL. Just saved me 12 billion hours of going through it by
hand. :) Life is good.

Doug Robbins - Word MVP said:
The following will do it on a Windows machine; no guarantee about a Mac

Dim i As Long, myrange As Range
i = 1
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{2}:[0-9]{2}:[0-9]{2}", _
MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Selection.MoveRight wdCharacter, 1
myrange.Text = Left(myrange.Text, 6) & Format(i, "0#")
i = i + 1
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

Carol said:
Hi, I'm figuring this is probably an easy thing to do...for someone who
has a clue. Unfortunately, I don't.

What I'd like to do (and I'm using a Mac/Word2004) is this:

find 12:00:00 and change it to 12:01:00 (or 12:00:01, doesn't matter)
and then the next instance 12:00:02 and so on through 59.

Is this possible using MS Word? (I also have Virtual PC, which lets me
emulate WIndows apps, and tried a piece of shareware I found online, but
never could get it to work right) I don't know how macros and VBA works;
have never used it or figured it out. ::shrug::

What I'm doing is importing flat text files into a WordPress database,
and one of the fields is date/time. I've got thousands of files, and
each time field needs to be a second off the next for this to work right.

Thank you. :)
 

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