ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Determine which commandbar called a function (https://www.excelbanter.com/excel-programming/418854-determine-commandbar-called-function.html)

Sgt Waddle

Determine which commandbar called a function
 
Hello,

I have been using the following function to change the faceid on a
commandbar button once it has been clicked:

Function ChangeFace()
Dim OldCTRL

Set OldCTRL =
CommandBars("SHOW").Controls(CommandBars.ActionCon trol.Caption)

OldCTRL.FaceId = 1087

OldCTRL.Style = msoButtonIconAndCaptionBelow
End Function

The function is called when each button is clicked.

the line Set OldCTRL = CommandBars("SHOW").Controls
CommandBars.ActionControl.Caption) sets which button on the commandbar named
SHOW called the function.

I would like to be able to capture which commandbar and which button called
the function so I can use the same function from different commandbars.

Something like (pseudo code)
Set OldCTRL =
CommandBars(ActiveCommandBar).Controls(CommandBars .ActionControl.Caption)

Any help is greatly appreciated,
Kevin




Jim Cone[_2_]

Determine which commandbar called a function
 
Just use...
Set OldCtrl = Application.CommandBars.ActionControl
And...
OldCtrl.Parent will return the controls location, but there is no need for this in the situation you describe.
--
Jim Cone
Portland, Oregon USA



"Sgt Waddle"
wrote in message
Hello,
I have been using the following function to change the faceid on a
commandbar button once it has been clicked:

Function ChangeFace()
Dim OldCTRL
Set OldCTRL =
CommandBars("SHOW").Controls(CommandBars.ActionCon trol.Caption)
OldCTRL.FaceId = 1087
OldCTRL.Style = msoButtonIconAndCaptionBelow
End Function

The function is called when each button is clicked.
the line Set OldCTRL = CommandBars("SHOW").Controls
CommandBars.ActionControl.Caption) sets which button on the commandbar named
SHOW called the function.
I would like to be able to capture which commandbar and which button called
the function so I can use the same function from different commandbars.
Something like (pseudo code)
Set OldCTRL =
CommandBars(ActiveCommandBar).Controls(CommandBars .ActionControl.Caption)

Any help is greatly appreciated,
Kevin




Sqt Waddle

SOLVED Determine which commandbar called a function
 
A little Google and 'Bob's your uncle!'

I did not need to name the CommandBar

Function ChangeFace()
Application.CommandBars.ActionControl.Style = msoButtonIconAndCaptionBelow
Application.CommandBars.ActionControl.FaceId = 1087
End Function

Thanks!

"Sgt Waddle" wrote:

Hello,

I have been using the following function to change the faceid on a
commandbar button once it has been clicked:

Function ChangeFace()
Dim OldCTRL

Set OldCTRL =
CommandBars("SHOW").Controls(CommandBars.ActionCon trol.Caption)

OldCTRL.FaceId = 1087

OldCTRL.Style = msoButtonIconAndCaptionBelow
End Function

The function is called when each button is clicked.

the line Set OldCTRL = CommandBars("SHOW").Controls
CommandBars.ActionControl.Caption) sets which button on the commandbar named
SHOW called the function.

I would like to be able to capture which commandbar and which button called
the function so I can use the same function from different commandbars.

Something like (pseudo code)
Set OldCTRL =
CommandBars(ActiveCommandBar).Controls(CommandBars .ActionControl.Caption)

Any help is greatly appreciated,
Kevin




Sqt Waddle[_2_]

Determine which commandbar called a function
 
Jim,

I didn't see your reply until after I solved it.

Thanks for taking the time to reply.
Kevin

"Jim Cone" wrote:

Just use...
Set OldCtrl = Application.CommandBars.ActionControl
And...
OldCtrl.Parent will return the controls location, but there is no need for this in the situation you describe.
--
Jim Cone
Portland, Oregon USA



"Sgt Waddle"
wrote in message
Hello,
I have been using the following function to change the faceid on a
commandbar button once it has been clicked:

Function ChangeFace()
Dim OldCTRL
Set OldCTRL =
CommandBars("SHOW").Controls(CommandBars.ActionCon trol.Caption)
OldCTRL.FaceId = 1087
OldCTRL.Style = msoButtonIconAndCaptionBelow
End Function

The function is called when each button is clicked.
the line Set OldCTRL = CommandBars("SHOW").Controls
CommandBars.ActionControl.Caption) sets which button on the commandbar named
SHOW called the function.
I would like to be able to capture which commandbar and which button called
the function so I can use the same function from different commandbars.
Something like (pseudo code)
Set OldCTRL =
CommandBars(ActiveCommandBar).Controls(CommandBars .ActionControl.Caption)

Any help is greatly appreciated,
Kevin






All times are GMT +1. The time now is 12:03 AM.

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