+ Reply to Thread
Results 1 to 6 of 6

Use of control button in Excel macro

  1. #1
    Registered User
    Join Date
    11-15-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    23

    Use of control button in Excel macro

    I'm writing a macro where, after some initial set up, a spreadsheet is activated and the user inputs some details in certain cells. The macro will use these values to carry out a series of calculations. I want to put a control command button on the worksheet which the user can click on once the values have been filled in to resume the macro, but I'm not sure how to reference the button in the vba code or how the vba code can determine when the button has been clicked.

    Grateful for assistance.

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Use of control button in Excel macro

    I have attached a very simple example. The macro MAIN prompts the user to perform actions and then to press the button. The macro then spins in a loop, waiting for the button to be pressed. Once the user has pressed the button, the macro detects the press and proceeds.

    This is made possible by the DoEvents statement. It allows focus to by shared between the macro and the user.
    Attached Files Attached Files
    Last edited by Jakobshavn; 11-15-2012 at 09:14 AM. Reason: verbiage
    Gary's Student

  3. #3
    Registered User
    Join Date
    11-15-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Use of control button in Excel macro

    Thank you. This is exactly what I needed.

    This is an excellent forum. I put the same query on what Microsoft now offers as its community help and received a totally useless reply!

  4. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Use of control button in Excel macro

    Thanks for the feedback!

  5. #5
    Registered User
    Join Date
    11-15-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Use of control button in Excel macro

    Just one other question: where can I access the Properties of Button1? Eg to change its name or alter the text/font?

  6. #6
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Use of control button in Excel macro

    Its only a Forms Button, so its properties are limited. Right-click the button and select Edit Text or Format Control.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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