Consulting

Results 1 to 10 of 10

Thread: Excel GUI : Activate a button from macro

  1. #1

    Excel GUI : Activate a button from macro

    Hello Friends

    Thank you for your replies for my previous querries.

    Could anybody please let me know how can I invoke a button from macro?

    To be more specific, I have two buttons in my excel file and each of these buttons contain different macro codes.
    Beginning with 1st button, if certain condition comes in its macro code then 2nd button should be activated. So then I can have further chance to run another macro from this 2nd (now activated) button and analyse the result in a better way.
    Bydefault 2nd button should be deactivated, so nobody can begin using this button.

    Thank you for your replied in advance.

    Kind Regards
    Vishalkumar

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    An example

    [vba]

    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "H1" '<== change to suit

    On Error GoTo ws_exit
    Application.EnableEvents = False

    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    With Target
    If IsNumeric(.Value) Then
    If .Value > 0 Then
    Me.Buttons("Button 1").Visible = True
    Me.Buttons("Button 2").Visible = False
    Else
    Me.Buttons("Button 1").Visible = False
    Me.Buttons("Button 2").Visible = True
    End If
    End If
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub
    [/vba]

    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.

  3. #3
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    You would probably be better off hiding the button! like this:
    [VBA]
    Option Explicit
    Private Sub CommandButton1_Click()
    Me.CommandButton1.Visible = False
    MsgBox "New Button activated"
    Me.CommandButton2.Visible = True
    End Sub
    Private Sub CommandButton2_Click()
    Me.CommandButton2.Visible = False
    MsgBox "New Button Activated"
    Me.CommandButton1.Visible = True
    End Sub
    [/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Ouch!, touche'
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    Hi Xld
    Hi Simon

    Great help once again

    Thanx
    VT


    P.S. by the way, why Ouch, Touche'

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Because we have this joke about giving the same answers, and stepping on ecah others toes. We did again here, so ouch for the toes, touche for the same answer.

  7. #7
    That s really funny
    Thanx anyways.

  8. #8
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Yes Bob, but as always i have to conceed the space to you as your solutions are fuller and styled with much more finesse!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Aah! If you would stop being a lazy git and stop laying on your back, you might beat me (I can't get smilies)

  10. #10
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    With comments like that i'm not suprised you can't get smiles!

    Lol
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

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