+ Reply to Thread
Results 1 to 6 of 6

UserForm with "Cancel" and "Proceed" buttons

  1. #1
    Registered User
    Join Date
    12-02-2016
    Location
    Germany
    MS-Off Ver
    2010 and 2013
    Posts
    21

    UserForm with "Cancel" and "Proceed" buttons

    Hi all,
    I stuck with an issue in an input box before an excel file gets opened.
    User can optionally enter a number code into a field, which then will be added to the file name.
    This works as intended.
    Now I wanted to fine tune the whole thing a bit.

    I have two buttons "Cancel" (CommandButton1) and "Proceed" (CommandButton2) on my userform

    Now I want the cancel button to simply cancel the main macro, end / exit the sub and go back to the origin excel sheet.
    This works well.

    BUT
    The Proceed button which is supposed to continue with the rest of the macro, either with a value in the input field or without, does not do what I want it to do :-)

    Either the proceed button also goes back to the origin excelsheet or the cancel button also proceeds with the main macro to browse for a file .

    See screenshot of the UserForm, the code behind it and the main macro code
    Macro_Cancel_Proceed.JPG

    Thanks upfront for your help

  2. #2
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: UserForm with "Cancel" and "Proceed" buttons

    Why don't you make code that will call your UserForm with Cancel and Processed buttons (outside your main macro).
    Then you could define your needs in CommandButton1_Click and CommandButton2_Click. If Cancel wiil be pressed - nothing will happen. If Proceed will be pressed - main macro will start.
    Lets say you start with this sub
    Please Login or Register  to view this content.
    Then write code for two buttons:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-02-2016
    Location
    Germany
    MS-Off Ver
    2010 and 2013
    Posts
    21

    Re: UserForm with "Cancel" and "Proceed" buttons

    Hi Kasan
    hmm, not sure I do understand that.
    I have already a button on the main excel sheet, which opens the main macro.
    OpenExcelsheet.JPG
    Upon clicking on this button, the UserForm1 gets opened

    Code within the main macro:
    UserForm1.Show 1

    ActiveSheet.Range("g3").Value = UserForm1.TextBox1
    Unload UserForm1

    But user should be able to either cancel the whole task, or to proceed to open the windows explorer, (no matter whether they did put in a code in the TextBox1 or not) and to browse for the file they need

    Am I missing something?

  4. #4
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: UserForm with "Cancel" and "Proceed" buttons

    Now your main macro show userform, but yiu could remove this part from main macro and show user form from separete small macro. Then if you press one button - your main macro will start. You can bind your button on a sheet to run macro that will only show userform.

  5. #5
    Registered User
    Join Date
    12-02-2016
    Location
    Germany
    MS-Off Ver
    2010 and 2013
    Posts
    21

    Re: UserForm with "Cancel" and "Proceed" buttons

    oh - ok. Will try this
    Thanks!!!

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: UserForm with "Cancel" and "Proceed" buttons

    Hi,

    I would suggest you add a property to your userform to store whether it was cancelled. Your Cancel button would set the property to True and then hide the form whereas the proceed button merely hides the form. The calling routine may thus check the cancelled property and, if it is true, unload the form and exit. If not, it reads the value of the textbox and then unloads the form before proceeding.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

+ 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. Replies: 5
    Last Post: 02-05-2019, 12:03 AM
  2. [SOLVED] Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box
    By Kenny Blackwell in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 08-31-2015, 10:00 AM
  3. "Add Row" and "Remove Row" Buttons... adding rows with formulas down filled
    By excelatnothing in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-15-2015, 02:44 AM
  4. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  5. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  6. Excel VBA Code to make my Toggle Buttons output "Yes" or "No" to their cells
    By mebanet in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-06-2013, 06:14 AM

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