Results 1 to 6 of 6

Thread: Command Button

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    3

    Command Button

    I've got a form which contains a command button.

    On my excel spreadsheet i've got another command button which calls the form.

    What i want to do is when i click the command button on the spreadsheet it calls the form and then runs the command button code. (Just like clicking the command button on the form)

    Please help!!v

    Thanks
    Last edited by gazza52_2000; Dec 21st, 2005 at 04:58 AM.

  2. #2
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Command Button

    Wrong forum, you need the office development forum

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Command Button

    In the Excel CommandButton click event, do something like:

    FormName.Show

    That will load and show the UserForm.

    Then, in the UserForm_Activate event, call the CommandButton click event, like:

    Call CommandButtonX_Click()


    It isn't the best practice calling a Controls Click (or other) event, so what I would suggest
    is creating a Sub (or Function if required) and call that from the Forms CommandButton click event,
    and also call it from the UserForm Activate event (and not directly, such as Call CommandButtonX_Click()).

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    3

    Re: Command Button

    Bruce

    I've got the form to show up ok.

    I'm confused as to where to place the Call CommandButtonX_Click().

    You say to add this to the UserForm_Activate event. I do not know where i can find this?. Is this the forms code? If so where would i place this command within the code?.

    Thanks again

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Command Button

    Moved from Classic VB forum.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Command Button

    In either your Sheet code or Workbook code you have your sheets commandbutton code to show the userform. After you click it behind your userform code you will have available to you the UserForm_Activate event procedure. This is where you could call the commandbutton click event but if you switch between the userform and the spreadsheet back and forth then the code for the command button will be run each and every time it "Activates" the userform.
    VB Code:
    1. Private Sub UserForm_Activate()
    2.     Call CommandButton1_Click
    3. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width