Results 1 to 2 of 2

Thread: [WORD] Temporarily store a varaible

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    1

    [WORD] Temporarily store a varaible

    Hi all. I have stored in my normal.dot a 6 macros that I need to run in succession. Each macro has an InputBox command that retrieves a variable from the user for the number of times to loop. Let's assume I enter the number "8". The next macro in succession that I need to run also needs to loop the same number of times, and the one following that does also... and so on. Is there a way for me to save the variable from the first InputBox statement so I don't have to keep reentering it with the next 6 macros that I need to run?

    Dim Message, Title, Default, IterationCount
    Message = "How many iterations do you wish to perform?" ' Set prompt.
    Title = "Iterations" ' Set title.
    Default = "1" ' Set default.

    IterationCount = InputBox(Message, Title, Default)

    For LoopCount = 1 To IterationCount 'Loop
    .
    .
    .
    Next LoopCount

  2. #2
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: [WORD] Temporarily store a varaible

    Change the scope of your Count variable:

    Code:
    Dim IterationCount As Integer
    
    Private Sub sub1()
        IterationCount = InputBox("How many iterations?", "Iterations", 1)
        '...
        Call sub2
    End Sub
    
    Private Sub sub2()
        MsgBox IterationCount
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width