+ Reply to Thread
Results 1 to 6 of 6

Pausing a Macro During Execution

Hybrid View

  1. #1
    Registered User
    Join Date
    04-30-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    38

    Pausing a Macro During Execution

    Hi,

    I have a macro that runs when the user selects an item from a drop down menu.I need to pause until the user fills in information - min and max values - in two cells. I would like the macro to detect when the user has filled in both cells and then resume the execution of the macro. Can anyone please tell me how to do this? Thank you.

    Also I would like to create a drop down menu on the fly in a specific cell via the macro. Is this possible? If yes, can you please suggest how? Thank you.

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,979

    Re: Pausing a Macro During Execution

    Here's an example of how I do it. We start at the end of my current macro, go to Pauser, create two buttons to activate two other macros (choice for the user). After they choose, KillButts kills the buttons, then off to the next macro ("Resumer1"):
     PT.ManualUpdate = False
            Application.ScreenUpdating = True
            'Turn off anything after our MFR month
            MsgBox "Please deselect any months following your MFR month in the MOS2 tab"
            Pauser
        End With
    
    Sub Pauser()
    Application.ScreenUpdating = False
    '1 is the first button, 2 is the second
        For j = 1 To 2
    
            'Where do we want the buttons, what macros should they run, and what should they say?
            With ActiveSheet.Buttons.Add(Choose(j, 200, 325), 40, 81, 50)
                .OnAction = Choose(j, "ResumeAuto", "KillButts")
                .Characters.Text = "Click here to " & Choose(j, "Resume", "Cancel") & " the Automation"
    
                'Color all of the font blue
                With .Characters(1, 36).Font
                    .Name = "Verdana"
                    .Size = 9
                    .Color = vbBlue
                End With
    
                'Color "Resume" and/or "Cancel" in red
                With .Characters(15, 6).Font
                    .FontStyle = "Bold"
                    .Color = vbRed
                End With
    
            End With
        Next
        'at this point, the automation stops until user hits "Resume", whereupon "ResumeAuto" runs.
        Application.ScreenUpdating = True
    End Sub
    
    Sub ResumeAuto()
        Killbutts
        Resumer1
    End Sub
    Sub Killbutts()
    'Activate sheet to delete autoshapes.
        Dim GetShape As Shape
    
        For Each GetShape In ActiveSheet.Shapes
            GetShape.Delete
        Next
    End Sub

  3. #3
    Registered User
    Join Date
    04-30-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Pausing a Macro During Execution

    Thank you Joimili. This is very interesting but overkill for my application at this time. I will however file it away for future reference. Once again, thank you..

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Pausing a Macro During Execution

    Another way:
        Range("A1").Value = Application.InputBox(Prompt:="Min?", Type:=1)
        Range("B1").Value = Application.InputBox(Prompt:="Max?", Type:=1)
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    04-30-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Pausing a Macro During Execution

    Thank you shg. This will do exactly what I need for my application. I did not even know this existed. Thank you.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Pausing a Macro During Execution

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1