Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default comandbar controls

Thankyou, thats makes sense.
Regards Robert
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
For Each Ctl In Me.Controls LongBeachGuy Excel Programming 1 December 29th 07 05:04 PM
Excel controls vs vba controls cmpcwil2[_6_] Excel Programming 3 April 19th 06 03:33 PM
ActiveX Controls vs Form Controls Alex Excel Discussion (Misc queries) 1 January 11th 06 08:46 AM
VB Controls Simon Shaw Excel Programming 2 November 18th 05 05:15 PM
Event procedures for controls added with Controls.Add John Austin[_4_] Excel Programming 1 March 9th 05 03:31 PM


All times are GMT +1. The time now is 07:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"