Results 1 to 28 of 28

Excel VBA - Disable Command button in sub?

Threaded View

  1. #1
    Registered User
    Join Date
    08-27-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    39

    Excel VBA - Disable Command button in sub?

    Hi, In my project I have a command bar which has 3 buttons. Enable Reminder, Time Reminder, Disable Reminder
    I have the Enable Reminder and Disable reminder buttons working and am currently working on getting time reminder working, my problem is I want this button to disable itself after the user has pressed it - how would I go about doing this?

    Currently this is the code I have for this command button.

    Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
    Dim cmbBar As CommandBar
    Dim cmbControl As CommandBarControl
    
    Set cmbBar = Application.CommandBars("Worksheet Menu Bar")
    Set cmbControl = cmbBar.Controls.Add(Type:=msoControlPopup, temporary:=True) 'Adds a Menu Item to the Menu Bar
        With cmbControl
            .Caption = "LLE Encryption Reminder" 'Names the Menu Item
        With .Controls.Add(Type:=msoControlButton) 'Adds a Dropdown Button to the Menu Item
            .Caption = "Enable Reminder" 'Adds a Description to the Menu Item
            .OnAction = "'EnableReminder'" 'Enable the Reminder
            .FaceId = 343 'Assigns an Icon to the Dropdown
            End With
        With .Controls.Add(Type:=msoControlButton) 'Adds a Dropdown Button to the Menu Item
            .Caption = "&Start Timer" 'Adds a Description to the Menu Item
            .OnAction = "'StartTimer'" 'Time the Reminder
            .FaceId = 126 'Assigns an Icon to the Dropdown
            End With
        With .Controls.Add(Type:=msoControlButton) 'Adds a Dropdown Button to the Menu Item
            .Caption = "Disable Reminder" 'Adds a Description to the Menu Item
            .OnAction = "'DisableReminder'" 'Disable the Reminder
            .FaceId = 342 'Assigns an Icon to the Dropdown
            End With
        End With
        
        TimerStart = False ' Set the timer start to false
        Response = 7 ' Set the response to no by default
        
    End Sub
    Private Sub StartTimer()
    If TimerStarted = False Then
        TimerStarted = True
        Response = 7
        RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
        Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
        Schedule:=True
        
        With cmbControl
            With .Controls("&Start Timer")
                .Controls("&Start Timer").Enabled = False
            End With
        End With
    End If
    End Sub
    As you can see I have tried to disable this button - However I'm not to sure if this is the right approach?
    Last edited by kickme93; 12-07-2013 at 05:47 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Disable command button not working in excel 2010
    By cneha1991 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-30-2011, 07:36 AM
  2. Disable command button
    By kuraitori in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-01-2009, 03:38 AM
  3. Disable Command Button
    By Hasnain in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2008, 01:32 PM
  4. Disable Command Button
    By Raj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-10-2006, 01:01 AM
  5. Disable command button
    By Mikeice in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2005, 06:05 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