PC Review


Reply
Thread Tools Rate Thread

comandbar controls

 
 
RobcPettit
Guest
Posts: n/a
 
      21st Oct 2008
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
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      21st Oct 2008
You'll need an OnTime macro for that. Get back if not sure how.

Regards,
Peter T

"RobcPettit" <(E-Mail Removed)> wrote in message
news:26587836-4bd6-45cc-ac27-(E-Mail Removed)...
> 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



 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      21st Oct 2008
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:=msoControlButton, _
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
<(E-Mail Removed)> 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

 
Reply With Quote
 
RobcPettit
Guest
Posts: n/a
 
      21st Oct 2008
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
 
Reply With Quote
 
RobcPettit
Guest
Posts: n/a
 
      21st Oct 2008
Thankyou, thats makes sense.
Regards Robert
 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      21st Oct 2008
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" <(E-Mail Removed)> wrote in message
news:61c42ab3-7ef6-43d6-aadb-(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controls.Count, Controls.IsSynchronized, and Controls.SyncRoot Nathan Sokalski Microsoft ASP .NET 4 5th Sep 2007 04:27 AM
Change a controls Border (width and color) on standard Winform Controls aarongoodman@gmail.com Microsoft C# .NET 0 26th Apr 2006 07:02 PM
Message box breaks owner draw controls in .NET controls used as ActiveX controls (again) Clive Dixon Microsoft Dot NET Framework Forms 0 26th May 2004 10:15 AM
How to force the child controls OnClick event before the parent controls CreateChildControls method? Arulraja Microsoft ASP .NET 3 17th Oct 2003 05:22 PM
Custom User Controls and dynamically created web controls events not firing Nicole Microsoft Dot NET Framework 0 25th Sep 2003 10:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:21 PM.