+ Reply to Thread
Results 1 to 8 of 8

Stop a running macro

Hybrid View

  1. #1
    Registered User
    Join Date
    09-15-2008
    Location
    Montana
    Posts
    11

    Stop a running macro

    Hi; I have a macro that uses InputBox for the user to provide data. Once the macro is started you can't stop it until it finishes.
    How can I stop the macro using the ESC key or can I assign a key to stop the macro.
    Thanks

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    ctrl+break perhaps?

  3. #3
    Registered User
    Join Date
    09-15-2008
    Location
    Montana
    Posts
    11
    Thank you that works.
    Is there a way to insert a line of code to assign say, the
    F4 key or other key combinations to stop the macro?

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I would think that your code is writen so that it won't stop until there is an input by the user. Post your code, remember to use Code Tags.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    09-15-2008
    Location
    Montana
    Posts
    11
    This was my first attemp at writing code. These lines are only for the first value. I have 20 additional InputBox statements. The reason for a method to stop the macro is many individuals running the macro and getting interrupted while inputing data.

    Sub Fill01()
    Worksheets("SINGLE PHASE CONSTRUCTION").Activate
        Dim UserEntry As String
        UserEntry = InputBox("What is the W/O #?", "INPUT W/O")
        If UserEntry <> "" Then Range("B2").Value = UserEntry
    END SUB

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Test UserEntry for "Quit" or something similar.

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try this

    Option Explicit
    
    Sub Fill01()
        'Worksheets("SINGLE PHASE CONSTRUCTION").Activate
        Dim UserEntry As String
        UserEntry = InputBox("What is the W/O #?", "INPUT W/O")
        Select Case UserEntry
            Case "": Exit Sub
            Case Else: Range("B2").Value = UserEntry
        End Select
    End Sub

  8. #8
    Registered User
    Join Date
    09-15-2008
    Location
    Montana
    Posts
    11
    I tested and found that if you provide a "" (blank, no answer) it terminates the macro. That works, but sometimes we need to provide a blank answers so for our application it won't work. I'll pass the word on the Ctrl+Break, key strokes.
    Thanks to all for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Use Event Procedure and OnTime to Stop a Macro
    By Protiusmime in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-26-2008, 07:46 PM
  2. Running Excel 4.0 Macro in Excel 2007.
    By CdSlc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-26-2008, 10:46 AM
  3. Error Saving after running Macro
    By millen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2007, 09:14 AM
  4. Macro won't stop running!
    By wizard007 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-05-2007, 06:09 AM
  5. automatically running a macro by selecting a worksheet
    By aralebd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2006, 05:43 PM

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