+ Reply to Thread
Results 1 to 6 of 6

command button to open a window

  1. #1
    Registered User
    Join Date
    09-13-2008
    Location
    Montreal
    MS-Off Ver
    Office XP
    Posts
    80

    command button to open a window

    so now I konw how to create a command button, I need to figure out how I can make that command button open a user form when I click it

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello slmi1313,

    First, you need to create a macro to open the UserForm, and then attach the macro to your button.

    Macro Code to Display a UserForm
    Please Login or Register  to view this content.
    Replace UserForm1 with the name of your UserForm.

    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    Right Click your command button and select Assign Macro.... Double Click on ShowForm.

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    09-13-2008
    Location
    Montreal
    MS-Off Ver
    Office XP
    Posts
    80
    when I right click my command button I do not have the option to assign macro... what am I doing wrong

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello slmi1313,

    Since you didn't say which type of command button you were using, I gave you directions for the Forms type, the most common type. If you can't assign a macro to the button then you must be using a Control Toolbox command button. You will have have to place a call to the macro in the button's Click event procedure.
    Please Login or Register  to view this content.
    Installing the Macro Event Code

    1) Open the workbook and Right Click the command button.
    2) Select View Code
    3) Type in ShowForm
    4) Save the changes using CTRL+S

    Sincerely,
    Leith Ross

  5. #5
    Registered User
    Join Date
    09-13-2008
    Location
    Montreal
    MS-Off Ver
    Office XP
    Posts
    80
    How about if I create the command button in excel sheet 1 using the control toolbox, and I want the command button to open sheet 2 what would be the code for that.

    thanks

    like I said Im pretty new to excel

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello slmi1313,

    Will say your Control Toolbox command button is named CommandButton1 on Sheet1. Copy and add the code below to the command button and it will activate Sheet2.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

+ 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. Opening a webpage with VBA
    By wilro85 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-24-2008, 07:58 PM
  2. open Window explorer from Excel
    By Chris Baluyot in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-23-2008, 11:25 PM
  3. Open jpeg in new IE window
    By pards84 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-09-2008, 12:47 PM
  4. Replies: 2
    Last Post: 11-29-2007, 04:22 PM
  5. Open excel in new window?
    By Hippogriff in forum Excel General
    Replies: 6
    Last Post: 11-14-2006, 11:33 AM

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