Hi, I am trying to replace a particular string in a simple file and cannot seem to get it to work. There are no errors but all the time entries are replaced. Ultimately, I want to delete only the redundant time entries. This is a MS Word 2003 VB Macro. I've seen so much contradictory junk that I'm lost and the MS documentation is certainly no help ... Thanks in advance for any ideas ... EXAMPLE FILE: MONDAY 00:00 01:01 TUESDAY 03:24 03:24 03:28 WEDNESDAY 04:12 04:13 07:23 THURSDAY 00:30 00:30 CODE: Sub deltime() ' ' test5 Macro to Delete redundant time entries Selection.Find.MatchWildcards = True Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting ' With Selection.Find .Text = "[0-9][0-9]:[0-9][0-9]" .Forward = True .Wrap = wdFindContinue If Selection.Text = "03:24" Then Selection.Find.Replacement.Text = "ABC" End With ' Selection.Find.Execute Replace:=wdReplaceAll ' End Sub
Use: With Selection.Find .ClearFormatting .Replacement.ClearFormatting .MatchWildcards = True .Text = "(*^13)@" .Replacement.Text = "\1" .Forward = True .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll 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 "Spotty Boy" wrote in message news:ad27934e-e736-4137-a4dc-a59c9959c040@b1g2000hsg.googlegroups.com... > Hi, > > I am trying to replace a particular string in a simple file and cannot > seem to get it to work. There are no errors but all the time entries > are replaced. Ultimately, I want to delete only the redundant time > entries. This is a MS Word 2003 VB Macro. I've seen so much > contradictory junk that I'm lost and the MS documentation is certainly > no help ... Thanks in advance for any ideas ... > > EXAMPLE FILE: > > MONDAY > 00:00 > 01:01 > TUESDAY > 03:24 > 03:24 > 03:28 > WEDNESDAY > 04:12 > 04:13 > 07:23 > THURSDAY > 00:30 > 00:30 > > CODE: > > Sub deltime() > ' > ' test5 Macro to Delete redundant time entries > Selection.Find.MatchWildcards = True > Selection.Find.ClearFormatting > Selection.Find.Replacement.ClearFormatting > ' > With Selection.Find > .Text = "[0-9][0-9]:[0-9][0-9]" > .Forward = True > .Wrap = wdFindContinue > If Selection.Text = "03:24" Then > Selection.Find.Replacement.Text = "ABC" > End With > ' > Selection.Find.Execute Replace:=wdReplaceAll > ' > End Sub