ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA problem with CommandBars (https://www.excelbanter.com/excel-programming/368659-vba-problem-commandbars.html)

zuEgg

VBA problem with CommandBars
 
Hi.
I'm having problems writing a macro that creates a custom
CommandBarControl. I have to check if the CommandBarControl is empty
and then delete it.
Here is the code of what i'm doing:

Dim cbpop As CommandBarControl
Dim cbctl As CommandBarControl
Dim bExists As Boolean
bExists = False
For Each cbpop In Application.CommandBars("Worksheet Menu
Bar").Controls
If cbpop.Caption = "xxx" Then

' if the CommandBarControl is empty.........

Application.CommandBars("Worksheet Menu
Bar").Controls("xxx").Delete
End If
Next

I've been searching for long but i've not found any hint for solving
the problem.
Thanks,
Massimo


Die_Another_Day

VBA problem with CommandBars
 
What do you mean by "empty"?
You can check to see if it has been assigned to anthing.
Var1 = cbpop.OnAction
you can assign the control to the variable control and check if that is
empty...
Set cbpop = Application.CommandBars("Worksheet Menu
Bar").Controls("xxx")
if cbpop is nothing then
.....
end if

Does that get you anywhere?

Die_Another_Day

zuEgg wrote:
Hi.
I'm having problems writing a macro that creates a custom
CommandBarControl. I have to check if the CommandBarControl is empty
and then delete it.
Here is the code of what i'm doing:

Dim cbpop As CommandBarControl
Dim cbctl As CommandBarControl
Dim bExists As Boolean
bExists = False
For Each cbpop In Application.CommandBars("Worksheet Menu
Bar").Controls
If cbpop.Caption = "xxx" Then

' if the CommandBarControl is empty.........

Application.CommandBars("Worksheet Menu
Bar").Controls("xxx").Delete
End If
Next

I've been searching for long but i've not found any hint for solving
the problem.
Thanks,
Massimo



zuEgg

VBA problem with CommandBars
 

Die_Another_Day ha scritto:

What do you mean by "empty"?
You can check to see if it has been assigned to anthing.
Var1 = cbpop.OnAction
you can assign the control to the variable control and check if that is
empty...
Set cbpop = Application.CommandBars("Worksheet Menu
Bar").Controls("xxx")
if cbpop is nothing then
....
end if

Does that get you anywhere?

Die_Another_Day


the CommandBarControl can contain other CommandBarControls as sub
menus. With empty i mean check if the CommandBarControl has no items
contained in it


Les

VBA problem with CommandBars
 
When I want to clear off a custom CommandBarControl (like when the workbook
is closed), I use:

On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("xxx").Delete
On Error GoTo 0

Its simpler than searching.

--
Les Torchia-Wells


"zuEgg" wrote:

Hi.
I'm having problems writing a macro that creates a custom
CommandBarControl. I have to check if the CommandBarControl is empty
and then delete it.
Here is the code of what i'm doing:

Dim cbpop As CommandBarControl
Dim cbctl As CommandBarControl
Dim bExists As Boolean
bExists = False
For Each cbpop In Application.CommandBars("Worksheet Menu
Bar").Controls
If cbpop.Caption = "xxx" Then

' if the CommandBarControl is empty.........

Application.CommandBars("Worksheet Menu
Bar").Controls("xxx").Delete
End If
Next

I've been searching for long but i've not found any hint for solving
the problem.
Thanks,
Massimo



Tom Ogilvy

VBA problem with CommandBars
 
if the CommandBarControl is empty.........

would be

if cbPop.controls.count = 0 then


--
Regards,
Tom Ogilvy



"zuEgg" wrote:


Die_Another_Day ha scritto:

What do you mean by "empty"?
You can check to see if it has been assigned to anthing.
Var1 = cbpop.OnAction
you can assign the control to the variable control and check if that is
empty...
Set cbpop = Application.CommandBars("Worksheet Menu
Bar").Controls("xxx")
if cbpop is nothing then
....
end if

Does that get you anywhere?

Die_Another_Day


the CommandBarControl can contain other CommandBarControls as sub
menus. With empty i mean check if the CommandBarControl has no items
contained in it



zuEgg

VBA problem with CommandBars
 

Tom Ogilvy ha scritto:

if the CommandBarControl is empty.........

would be

if cbPop.controls.count = 0 then


Thank you very much. my problem is solved! I wasn't able to find the
count property because the vba editor don't put it in the property list
that appears pressing ctrl+space.

Thanks again :)



All times are GMT +1. The time now is 04:40 AM.

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