Announcement

Collapse
No announcement yet.

How to run all macros once only in word document

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to run all macros once only in word document



    Hi there,

    I have created some macros for setup invoice. but I want to use all macros once only as if by mistake i use more than once all setup changes and unexpected result is coming up. so will you please guide me how to put vba code to run each macros once only.

    Thanks you and Regards,
    Niky

  • #2
    Hi Niky,

    There are a couple of ways to achieve this.

    Create a new subroutine and call all the macros from that.

    Or...

    Define a Boolean variable i.e. blnMyMacroRun As Boolean for each macro. Which you set to True at the end of the macro. At the start of the Macro check whether it is True and Exit Sub if it is.

    Code:
    Option Explicit
    ' Macros run booleans.
    Private blnMyMacroRun As Boolean
    
    Private Sub MyMacro()
    
    If blnMyMacroRun = True Then Exit Sub
    
    ' Do some stuff.
    .
    .
    .
     
    blnMyMacroRun = True
    
    End Sub
    Regards,

    Tom Rowe

    Comment


    • #3


      Thank you Tom

      Comment

      Working...
      X