Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default passing commandbars to a procedure

I have a procedure that takes a commandbar object as it's argurment:

Sub modify_insert_delete_buttons(cbar As CommandBar, Optional delete As
Boolean = False)

It modifies Excel's existing Insert Rows and Delete Rows buttons on various
Excel commandbars including the Edit menu and the Cells right-click menu.
In the procedure I need to use FindControl which seems to be only available
with CommandbarPopups, not Commandbars. In order to pass the Edit menu to
my routine I've done this in the calling procedu

Dim cbar As CommandBar
Set cbar = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30003).Controls(1).Parent 'Edit menu

Is there a better way to do this, without calling the Parent of a Control on
the Edit menu? It seems like the following should work, but it gives a type
mismatch error:

Set cbar = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30003)

Again, the way I'm doing it works, I just wonder if there's a better way.

thanks,

Doug


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default passing commandbars to a procedure

Doug,

I suspect you overlooked cbar's type declaration. It should be declared as a
CommandBarControl instead of a CommandBar. The following returns "&Edit" for
me:

With Application
Set cbar = .CommandBars(1).FindControl(ID:=30003)
MsgBox cbar.Caption
End With

Interestingly, (and this is just my take on it) the parent of a menu item is
NOT the CommandBarPopup (i.e. "Edit" in this case) but the dropdown that the
menu items are attached to. This is a modified popup Commandbar. That is why
the following code didn't return an error with cbar declared as CommandBar:

Set cbar = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30003).Controls(1).Parent


Note that the following returns "&Edit" which (IMO) proves my point. And
note the double "Parent":

With Application
Set cbar = .CommandBars(1).FindControl(ID:=30003).Controls(1) .Parent.Parent
MsgBox cbar.Caption
End With

However, it's not that simple. The first level child to the "Edit" menu
should (according to my theory) be the dropdown. But, since it is not a
Control the following returns the caption of the first control on the
dropdown intstead (i.e. "Can't &Undo"):

With Application
Set cbar = .CommandBars(1).FindControl(ID:=30003)
MsgBox cbar.Controls(1).Caption
End With


Regards,
Greg

"Doug Glancy" wrote:

I have a procedure that takes a commandbar object as it's argurment:

Sub modify_insert_delete_buttons(cbar As CommandBar, Optional delete As
Boolean = False)

It modifies Excel's existing Insert Rows and Delete Rows buttons on various
Excel commandbars including the Edit menu and the Cells right-click menu.
In the procedure I need to use FindControl which seems to be only available
with CommandbarPopups, not Commandbars. In order to pass the Edit menu to
my routine I've done this in the calling procedu

Dim cbar As CommandBar
Set cbar = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30003).Controls(1).Parent 'Edit menu

Is there a better way to do this, without calling the Parent of a Control on
the Edit menu? It seems like the following should work, but it gives a type
mismatch error:

Set cbar = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30003)

Again, the way I'm doing it works, I just wonder if there's a better way.

thanks,

Doug



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default passing commandbars to a procedure

Greg,

Thanks, but I didn't really overlook the type declaration. Declaring it as
a CommandBarControl wouldn't work because I need to pass a Commandbar to the
subroutine, so that the subroutine can use FindControl on the Commandbar. I
was just wondering if there was a better way to be able to set Edit and
other menus as commandbars.

Your analysis about the "intermediate parent" is interesting. I fooled
around with it to see if I could use it for this, but didn't come with
anything.
Thanks,

Doug

"Greg Wilson" wrote in message
...
Doug,

I suspect you overlooked cbar's type declaration. It should be declared as
a
CommandBarControl instead of a CommandBar. The following returns "&Edit"
for
me:

With Application
Set cbar = .CommandBars(1).FindControl(ID:=30003)
MsgBox cbar.Caption
End With

Interestingly, (and this is just my take on it) the parent of a menu item
is
NOT the CommandBarPopup (i.e. "Edit" in this case) but the dropdown that
the
menu items are attached to. This is a modified popup Commandbar. That is
why
the following code didn't return an error with cbar declared as
CommandBar:

Set cbar = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30003).Controls(1).Parent


Note that the following returns "&Edit" which (IMO) proves my point. And
note the double "Parent":

With Application
Set cbar =
.CommandBars(1).FindControl(ID:=30003).Controls(1) .Parent.Parent
MsgBox cbar.Caption
End With

However, it's not that simple. The first level child to the "Edit" menu
should (according to my theory) be the dropdown. But, since it is not a
Control the following returns the caption of the first control on the
dropdown intstead (i.e. "Can't &Undo"):

With Application
Set cbar = .CommandBars(1).FindControl(ID:=30003)
MsgBox cbar.Controls(1).Caption
End With


Regards,
Greg

"Doug Glancy" wrote:

I have a procedure that takes a commandbar object as it's argurment:

Sub modify_insert_delete_buttons(cbar As CommandBar, Optional delete As
Boolean = False)

It modifies Excel's existing Insert Rows and Delete Rows buttons on
various
Excel commandbars including the Edit menu and the Cells right-click menu.
In the procedure I need to use FindControl which seems to be only
available
with CommandbarPopups, not Commandbars. In order to pass the Edit menu
to
my routine I've done this in the calling procedu

Dim cbar As CommandBar
Set cbar = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30003).Controls(1).Parent 'Edit menu

Is there a better way to do this, without calling the Parent of a Control
on
the Edit menu? It seems like the following should work, but it gives a
type
mismatch error:

Set cbar = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30003)

Again, the way I'm doing it works, I just wonder if there's a better way.

thanks,

Doug





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default passing commandbars to a procedure

If you want the parent of a control then you have to use .Parent as far as I
can see Doug.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Doug Glancy" wrote in message
...
Greg,

Thanks, but I didn't really overlook the type declaration. Declaring it

as
a CommandBarControl wouldn't work because I need to pass a Commandbar to

the
subroutine, so that the subroutine can use FindControl on the Commandbar.

I
was just wondering if there was a better way to be able to set Edit and
other menus as commandbars.

Your analysis about the "intermediate parent" is interesting. I fooled
around with it to see if I could use it for this, but didn't come with
anything.
Thanks,

Doug

"Greg Wilson" wrote in message
...
Doug,

I suspect you overlooked cbar's type declaration. It should be declared

as
a
CommandBarControl instead of a CommandBar. The following returns "&Edit"
for
me:

With Application
Set cbar = .CommandBars(1).FindControl(ID:=30003)
MsgBox cbar.Caption
End With

Interestingly, (and this is just my take on it) the parent of a menu

item
is
NOT the CommandBarPopup (i.e. "Edit" in this case) but the dropdown that
the
menu items are attached to. This is a modified popup Commandbar. That is
why
the following code didn't return an error with cbar declared as
CommandBar:

Set cbar = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30003).Controls(1).Parent


Note that the following returns "&Edit" which (IMO) proves my point. And
note the double "Parent":

With Application
Set cbar =
.CommandBars(1).FindControl(ID:=30003).Controls(1) .Parent.Parent
MsgBox cbar.Caption
End With

However, it's not that simple. The first level child to the "Edit" menu
should (according to my theory) be the dropdown. But, since it is not a
Control the following returns the caption of the first control on the
dropdown intstead (i.e. "Can't &Undo"):

With Application
Set cbar = .CommandBars(1).FindControl(ID:=30003)
MsgBox cbar.Controls(1).Caption
End With


Regards,
Greg

"Doug Glancy" wrote:

I have a procedure that takes a commandbar object as it's argurment:

Sub modify_insert_delete_buttons(cbar As CommandBar, Optional delete As
Boolean = False)

It modifies Excel's existing Insert Rows and Delete Rows buttons on
various
Excel commandbars including the Edit menu and the Cells right-click

menu.
In the procedure I need to use FindControl which seems to be only
available
with CommandbarPopups, not Commandbars. In order to pass the Edit menu
to
my routine I've done this in the calling procedu

Dim cbar As CommandBar
Set cbar = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30003).Controls(1).Parent 'Edit menu

Is there a better way to do this, without calling the Parent of a

Control
on
the Edit menu? It seems like the following should work, but it gives a
type
mismatch error:

Set cbar = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30003)

Again, the way I'm doing it works, I just wonder if there's a better

way.

thanks,

Doug







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default passing commandbars to a procedure

Doug,

Your preferred way will work, but cBar is a CommandbarControl in this case,
not type Commandbar.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Doug Glancy" wrote in message
...
I have a procedure that takes a commandbar object as it's argurment:

Sub modify_insert_delete_buttons(cbar As CommandBar, Optional delete As
Boolean = False)

It modifies Excel's existing Insert Rows and Delete Rows buttons on

various
Excel commandbars including the Edit menu and the Cells right-click menu.
In the procedure I need to use FindControl which seems to be only

available
with CommandbarPopups, not Commandbars. In order to pass the Edit menu to
my routine I've done this in the calling procedu

Dim cbar As CommandBar
Set cbar = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30003).Controls(1).Parent 'Edit menu

Is there a better way to do this, without calling the Parent of a Control

on
the Edit menu? It seems like the following should work, but it gives a

type
mismatch error:

Set cbar = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30003)

Again, the way I'm doing it works, I just wonder if there's a better way.

thanks,

Doug






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
Passing a Function name as a procedure argument [email protected] Excel Programming 9 November 7th 05 02:55 PM
Passing an array or recordset to a stored procedure Paul Robinson Excel Programming 1 December 2nd 04 05:15 AM
Passing Userform as an argument to a procedure Howard Kaikow Excel Programming 12 October 24th 03 03:24 PM
Passing properties to a procedure Matt McQueen[_2_] Excel Programming 1 July 30th 03 04:44 PM
Passing a Password to a VBA Procedure Orlando Magalhães Filho Excel Programming 0 July 9th 03 05:41 AM


All times are GMT +1. The time now is 09:07 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"