ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   comandbar controls (https://www.excelbanter.com/excel-programming/418846-comandbar-controls.html)

RobcPettit[_2_]

comandbar controls
 
Hi, Ive biult a tool bar with commandbar controls. If I click one of
my command buttons, it fires the onaction and runs my macro. I want my
macro to delete this command button and a couple of others. I can
delete he others ok, but not the one clicked. Im using 'Set cbct1 =
CommandBars("Customer").FindControl(Tag:="Six")
cbct1.Delete' for each one. Ive been trying to deselect the button,
but cant work out how. Ive tried enabling and disabling, but this
didnt work. Any ideas
Regards Robert

Peter T

comandbar controls
 
You'll need an OnTime macro for that. Get back if not sure how.

Regards,
Peter T

"RobcPettit" wrote in message
...
Hi, Ive biult a tool bar with commandbar controls. If I click one of
my command buttons, it fires the onaction and runs my macro. I want my
macro to delete this command button and a couple of others. I can
delete he others ok, but not the one clicked. Im using 'Set cbct1 =
CommandBars("Customer").FindControl(Tag:="Six")
cbct1.Delete' for each one. Ive been trying to deselect the button,
but cant work out how. Ive tried enabling and disabling, but this
didnt work. Any ideas
Regards Robert




Chip Pearson

comandbar controls
 
You can't delete the control while it is in use. You can use the
OnTime method to tell Excel to run a procedure as soon as it is done
with other requests. E.g.,

Option Explicit

Private pDeleteControl As Office.CommandBarControl

Sub CreateTheControl()
''''''''''''''''''''''
' create the control.
''''''''''''''''''''''
Dim C As Office.CommandBarButton
Set C = Application.CommandBars.ActiveMenuBar. _
Controls("Tools").Controls.Add(Type:=msoControlBut ton, _
temporary:=True)
With C
.Caption = "Click me"
.OnAction = "'" & ThisWorkbook.Name & "'!ClickProc"
.Tag = "TheTag"
End With
End Sub

Sub ClickProc()
'''''''''''''''''''''''''''
' called by OnAction.
' use OnTime to schedule
' the control for deletion.
'''''''''''''''''''''''''''
MsgBox "Clicked"
Set pDeleteControl = _
Application.CommandBars.FindControl(Tag:="TheTag")
Application.OnTime Now, "DeleteIt", , True
End Sub

Sub DeleteIt()
''''''''''''''''''''
' delete the control.
' called by OnTime.
''''''''''''''''''''
If Not pDeleteControl Is Nothing Then
pDeleteControl.Delete
Set pDeleteControl = Nothing
End If
End Sub


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Tue, 21 Oct 2008 11:19:06 -0700 (PDT), RobcPettit
wrote:

Hi, Ive biult a tool bar with commandbar controls. If I click one of
my command buttons, it fires the onaction and runs my macro. I want my
macro to delete this command button and a couple of others. I can
delete he others ok, but not the one clicked. Im using 'Set cbct1 =
CommandBars("Customer").FindControl(Tag:="Six")
cbct1.Delete' for each one. Ive been trying to deselect the button,
but cant work out how. Ive tried enabling and disabling, but this
didnt work. Any ideas
Regards Robert


RobcPettit[_2_]

comandbar controls
 
Thankyou for your reply. Is this were I set the macro to fire at a
certain time. If so how does it work with deleting the button. Im
thinking that on clicking the button, the ontime method is set, and
the button is released, because as far as the buttons concerned its
finished its task.
Regards Robert

RobcPettit[_2_]

comandbar controls
 
Thankyou, thats makes sense.
Regards Robert

Peter T

comandbar controls
 
Chip has provided a complete demo. Looking at the close timings of your
posts his may not have been visible to you.

Regards,
Peter T

"RobcPettit" wrote in message
...
Thankyou for your reply. Is this were I set the macro to fire at a
certain time. If so how does it work with deleting the button. Im
thinking that on clicking the button, the ontime method is set, and
the button is released, because as far as the buttons concerned its
finished its task.
Regards Robert





All times are GMT +1. The time now is 05:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com