+ Reply to Thread
Results 1 to 5 of 5

Activating/De-activating buttons

  1. #1
    Nash
    Guest

    Activating/De-activating buttons

    Is there a way to activate a macro button based on a value in a cell and then
    de-activating the button if the value does not match?

    Thanks,



  2. #2
    abcd
    Guest

    Re: Activating/De-activating buttons

    if the button objet vba's name is commandbutton1 on the Sheet1 object then:

    Sheet1.CommandButton1.Enabled = false ' or true

    the change event of this sheet may be used to detect a change on that sheet

    example:

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not (Intersect(Target, Range("A1")) Is Nothing) Then
    CommandButton1.Enabled = Not CommandButton1.Enabled
    End If
    End Sub

  3. #3
    Nash
    Guest

    Re: Activating/De-activating buttons

    How do I find the name of the button? Thanks,


    "abcd" wrote:

    > if the button objet vba's name is commandbutton1 on the Sheet1 object then:
    >
    > Sheet1.CommandButton1.Enabled = false ' or true
    >
    > the change event of this sheet may be used to detect a change on that sheet
    >
    > example:
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > If Not (Intersect(Target, Range("A1")) Is Nothing) Then
    > CommandButton1.Enabled = Not CommandButton1.Enabled
    > End If
    > End Sub
    >


  4. #4
    abcd
    Guest

    Re: Activating/De-activating buttons

    Usually, the name is written inside the button when created. But you
    also can find it in the VBA editor (the dropdown list: as you have
    "General" or "worksheet" you now have the button object in the list. )


  5. #5
    William Benson
    Guest

    Re: Activating/De-activating buttons

    If you mean a macro button on a command bar, I do not know how to do that
    because I think they are either visible (added to the command bar) or not. I
    don't think they can be disabled.


    Assuming the "macro button" is a command button on a worksheet, yes.

    Private Sub Worksheet_Change(ByVal Target As Range)

    'test this by changing the value in cell A1
    Const strTestValue = 5 'For example only

    If ActiveSheet.Range("A1") = AcceptValue Then
    CommandButton1.Enabled = True
    Else
    CommandButton1.Enabled = False
    End If

    End Sub



    "Nash" <[email protected]> wrote in message
    news:[email protected]...
    > Is there a way to activate a macro button based on a value in a cell and
    > then
    > de-activating the button if the value does not match?
    >
    > Thanks,
    >
    >




+ 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