Group:  Microsoft Word ยป microsoft.public.word.vba.beginners
Thread: Find/Replace with sequential number

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Find/Replace with sequential number
Carol <carCATLITTERolj12345[ at ]gmail.com> 17.07.2006 18:18:30
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. :)
--
To email, remove the kitty litter...
Re: Find/Replace with sequential number
"Greg Maxey" <gmaxey[ at ]mvps.org> 17.07.2006 19:04:23
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



Carol wrote:
[Quoted Text]
> 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. :)
> --
> To email, remove the kitty litter...

Re: Find/Replace with sequential number
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 17.07.2006 19:04:46
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" <carCATLITTERolj12345[ at ]gmail.com> wrote in message
news:WvQug.131781$dW3.38578[ at ]newssvr21.news.prodigy.com...
[Quoted Text]
> 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. :)
> --
> To email, remove the kitty litter...


Re: Find/Replace with sequential number
Carol <carCATLITTERolj12345[ at ]gmail.com> 17.07.2006 21:57:13
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.

In article <eddQiPdqGHA.4408[ at ]TK2MSFTNGP04.phx.gbl>,
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> wrote:

[Quoted Text]
> 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" <carCATLITTERolj12345[ at ]gmail.com> wrote in message
> news:WvQug.131781$dW3.38578[ at ]newssvr21.news.prodigy.com...
> > 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. :)
> > --
> > To email, remove the kitty litter...
--
To email, remove the kitty litter...

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net