Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Detrmine which command button was clicked

I have a workbook with more than twenty sheets. I
regularly add and delete sheets. I have created a custom
menu on the standard menu bar and a amcro to show all the
sheets by their name (Caption) on the menu everytime the
workbook is activated. The idea is to click the sheet name
on the menu to go to a given sheet . However, I am finding
it difficult to assign a single macro to OnAction property
which will determine which sheet was selected and then
activate that sheet.

Any help is appreciated

Thanks in anticipation

Jamal
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default Detrmine which command button was clicked

Jamal,

CommandBars.ActionControl

is the button that is pressed. You can access any of its properties,
along the lines of:

CommandBars.ActionControl.Caption

You could use it like

Sub SelectSheet()
Worksheets(CommandBars.ActionControl.Caption).Acti vate
End Sub

And assign that macro to all your commandbar buttons.

HTH,
Bernie
MS Excel MVP

"Jamal" wrote in message
...
I have a workbook with more than twenty sheets. I
regularly add and delete sheets. I have created a custom
menu on the standard menu bar and a amcro to show all the
sheets by their name (Caption) on the menu everytime the
workbook is activated. The idea is to click the sheet name
on the menu to go to a given sheet . However, I am finding
it difficult to assign a single macro to OnAction property
which will determine which sheet was selected and then
activate that sheet.

Any help is appreciated

Thanks in anticipation

Jamal



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Detrmine which command button was clicked

assuming the caption of the button is like Sheet1

Sub SheetButtonClick()
sName = Commandbars.ActionControl.Caption
Worksheets("sName").Activate
End Sub

--
Regards,
Tom Ogilvy


"Jamal" wrote in message
...
I have a workbook with more than twenty sheets. I
regularly add and delete sheets. I have created a custom
menu on the standard menu bar and a amcro to show all the
sheets by their name (Caption) on the menu everytime the
workbook is activated. The idea is to click the sheet name
on the menu to go to a given sheet . However, I am finding
it difficult to assign a single macro to OnAction property
which will determine which sheet was selected and then
activate that sheet.

Any help is appreciated

Thanks in anticipation

Jamal



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Detrmine which command button was clicked

Shouldn't have those quotes in there - apologies

Sub SheetButtonClick()
sName = Commandbars.ActionControl.Caption
Worksheets(sName).Activate
End Sub

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
assuming the caption of the button is like Sheet1

Sub SheetButtonClick()
sName = Commandbars.ActionControl.Caption
Worksheets("sName").Activate
End Sub

--
Regards,
Tom Ogilvy


"Jamal" wrote in message
...
I have a workbook with more than twenty sheets. I
regularly add and delete sheets. I have created a custom
menu on the standard menu bar and a amcro to show all the
sheets by their name (Caption) on the menu everytime the
workbook is activated. The idea is to click the sheet name
on the menu to go to a given sheet . However, I am finding
it difficult to assign a single macro to OnAction property
which will determine which sheet was selected and then
activate that sheet.

Any help is appreciated

Thanks in anticipation

Jamal





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Detrmine which command button was clicked

Thank you, Bernie and Tom. Both method works magic. Much
appreciated.

-----Original Message-----
Jamal,

CommandBars.ActionControl

is the button that is pressed. You can access any of its

properties,
along the lines of:

CommandBars.ActionControl.Caption

You could use it like

Sub SelectSheet()
Worksheets(CommandBars.ActionControl.Caption).Act ivate
End Sub

And assign that macro to all your commandbar buttons.

HTH,
Bernie
MS Excel MVP

"Jamal" wrote in

message
...
I have a workbook with more than twenty sheets. I
regularly add and delete sheets. I have created a custom
menu on the standard menu bar and a amcro to show all

the
sheets by their name (Caption) on the menu everytime the
workbook is activated. The idea is to click the sheet

name
on the menu to go to a given sheet . However, I am

finding
it difficult to assign a single macro to OnAction

property
which will determine which sheet was selected and then
activate that sheet.

Any help is appreciated

Thanks in anticipation

Jamal



.

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
Macro button gets bigger when clicked Snowskier Excel Discussion (Misc queries) 1 May 27th 10 09:36 PM
VBA button on Developer ribbon can not be clicked eliassal Excel Discussion (Misc queries) 2 December 20th 09 09:30 PM
Preventing a command button from being clicked twice NDBC Excel Discussion (Misc queries) 2 June 27th 09 01:22 AM
let a sub recognise the name of the button that has been clicked. Brotherwarren Excel Discussion (Misc queries) 2 March 18th 06 10:56 AM
Button event clicked problem Marek Cvrk Excel Programming 2 October 14th 03 05:47 PM


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

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

About Us

"It's about Microsoft Excel"