Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Find Function? [modified]

Find Function? [modified]

Scheduled Pinned Locked Moved Visual Basic
questionhelptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Harold_Wishes
    wrote on last edited by
    #1

    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 20

    With 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

    T 1 Reply Last reply
    0
    • H Harold_Wishes

      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 20

      With 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

      T Offline
      T Offline
      Tyquaun Hunter
      wrote on last edited by
      #2

      Try exit sub Tyquaun

      H 1 Reply Last reply
      0
      • T Tyquaun Hunter

        Try exit sub Tyquaun

        H Offline
        H Offline
        Harold_Wishes
        wrote on last edited by
        #3

        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.

        T 1 Reply Last reply
        0
        • H Harold_Wishes

          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.

          T Offline
          T Offline
          Tyquaun Hunter
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups