a Macro to loop a function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alphanj
    New Member
    • Jun 2010
    • 8

    a Macro to loop a function

    How can I use "loop" in my macro code. For example I want my macro to reruns back to first line of the code and repeats again.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by alphanj
    How can I use "loop" in my macro code. For example I want my macro to reruns back to first line of the code and repeats again.
    If I understand you correctly:
    Code:
    DoCmd.RunMacro "<Macro Name>", 2

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32634

      #3
      If you're in a Macro rather than VBA code (which isn't a good idea mind) then you can invoke the current macro using RunMacro.

      Comment

      • alphanj
        New Member
        • Jun 2010
        • 8

        #4
        Originally posted by NeoPa
        If you're in a Macro rather than VBA code (which isn't a good idea mind) then you can invoke the current macro using RunMacro.
        It is a VBA,
        I want to the function to be repeated again and again in the document till the end of document.
        I used this code:
        Code:
        Do Until ActiveDocument.Bookmarks("\Sel") = _
           ActiveDocument.Bookmarks("\EndOfDoc")
           '(Do something)
        Loop
        but when I run it, it does not finish at the end of document and star it from beginning and ther is no way to stop it.
        Last edited by NeoPa; Jun 29 '10, 02:45 PM. Reason: Please use the [CODE] tags provided.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32634

          #5
          Ctrl-Break can normally stop code executing.

          As for your code, I'm pleased it's VBA rather than Access Macros, yet I'm confused as to why you would ask such a question without including so many of the relevant details. It now appears that it is Word VBA we are dealing with.

          From your code, I see nothing that would ever move the selection forward, so am not surprised that it results in an interminable loop. How you should manage your loop depends on what you are doing and what you want. Without knowing either of these I cannot be of any further help at this time.

          Comment

          Working...