Find Function? [modified]
-
Hello, I am new to VB and need help on a specific question. I need to know if there is a find function in VB so that I can terminate a loop. Example, suppose I need to find all tildas (~) in a file from start to finish in MS-Word. I would like to use a find function (if it exist) in my test condition so that the program exits the loop when the last tilda is found. Below is a for loop that I hard coded to repeat so many times but I would prefer doing it a better way. Help is appreciated.
Sub test()
'
' test Macro
' Macro recorded 7/30/2006 by Harold-Wishes
'
Selection.Find.ClearFormatting
For Counter = 1 To 20With Selection.Find .Text = "'" .Replacement.Text = "'" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.TypeText Text:="'" Next
End Sub
-- modified at 7:36 Monday 31st July, 2006
-
Hello, I am new to VB and need help on a specific question. I need to know if there is a find function in VB so that I can terminate a loop. Example, suppose I need to find all tildas (~) in a file from start to finish in MS-Word. I would like to use a find function (if it exist) in my test condition so that the program exits the loop when the last tilda is found. Below is a for loop that I hard coded to repeat so many times but I would prefer doing it a better way. Help is appreciated.
Sub test()
'
' test Macro
' Macro recorded 7/30/2006 by Harold-Wishes
'
Selection.Find.ClearFormatting
For Counter = 1 To 20With Selection.Find .Text = "'" .Replacement.Text = "'" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.TypeText Text:="'" Next
End Sub
-- modified at 7:36 Monday 31st July, 2006
Try exit sub Tyquaun
-
Try exit sub Tyquaun
Hello, Could you clarify? I would like to remove the code below and have the loop stop when the last tilda is found. Currently I have it set to loop twenty times.
For Counter = 1 To 20
I know there is some boolean function for find, but I'm not getting the syntax correct.
-
Hello, Could you clarify? I would like to remove the code below and have the loop stop when the last tilda is found. Currently I have it set to loop twenty times.
For Counter = 1 To 20
I know there is some boolean function for find, but I'm not getting the syntax correct.
Try using regular expression. Once your value has been found exit the loop. Here is an article in MSDN http://support.microsoft.com/default.aspx?scid=kb;en-us;818802[^] -- modified at 15:27 Monday 31st July, 2006