Consulting

Results 1 to 3 of 3

Thread: Buttons to Start and Stop Macro

  1. #1
    VBAX Regular
    Joined
    Aug 2008
    Posts
    48
    Location

    Buttons to Start and Stop Macro

    Hi,

    How can I create buttons to start or stop VBA macros from the excel spreadsheet ?

    Thx

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You can use a button form the forms toolbar to start the macro, but you cannot (easily) have a b utton to top it, as it will work through to its conclusion.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Maybe something like
    [vba]
    Dim Test As Boolean

    Private Sub CommandButton1_Click()
    Test = True
    Range("a1") = 0
    Do Until Test = False
    Range("a1") = Range("a1") + 1
    DoEvents
    Loop
    End Sub

    Private Sub CommandButton2_Click()
    Test = False
    End Sub

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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