Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default How can enable and disable menuitems based on the type of sheet.

Hi,

First of all I thank Tom, Bernie and Norman for responding to my
posts in this group. Your responses helped me to wrap up the small
project that I am doing in excel. As a last task I am now doing a menu
for this project.I have created the menu and added it to the excel
file. The menu appears right before the help menu. The menu gets added
to the workbook when we open it. There are three sheets in this
workbook. But all the menuitems will not operate on all the three
sheets. Some work on first, some work on second, some work on third.
How can I disable the menuitems based on the sheet name. Thanks in
advance for all the help.

Shishi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default How can enable and disable menuitems based on the type of sheet.

Use the sheet activate / deactivate events. This example disables the
DataSort command. This is worksheet code: right click the sheet tab, select
view code and paste the code. Do this for each of the three sheets changing
the menu and control names so that the relevant menu items are disabled for
each sheet.

Private Sub Worksheet_Activate()
CommandBars(1).Controls("Data").Controls("Sort..." ).Enabled = False
End Sub


Private Sub Worksheet_Deactivate()
CommandBars(1).Controls("Data").Controls("Sort..." ).Enabled = True
End Sub

Hope this helps
Rowan

"shishi" wrote:

Hi,

First of all I thank Tom, Bernie and Norman for responding to my
posts in this group. Your responses helped me to wrap up the small
project that I am doing in excel. As a last task I am now doing a menu
for this project.I have created the menu and added it to the excel
file. The menu appears right before the help menu. The menu gets added
to the workbook when we open it. There are three sheets in this
workbook. But all the menuitems will not operate on all the three
sheets. Some work on first, some work on second, some work on third.
How can I disable the menuitems based on the sheet name. Thanks in
advance for all the help.

Shishi


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default How can enable and disable menuitems based on the type of sheet.

Hi,

Thank you Rowan for the reply. It works. great...However I have
couple of complications here.

1. Right now I have the Makemenu() procedure as below.
Private Sub Workbook_Open()
Call MakeMenu
End Sub
So it makes the menu whenever I open the workbook. The workbook opens
with last open sheet active. I have six items in the menu. Two of them
should be deactivated in Sheet2 and one should be deactivated in
Sheet1. But at first when I open the workbook regardless of which
sheet I am on, I see that all the menu items are activated. After that,
if I click on the Sheet1 or Sheet2 the menu show up with itmes
activated or deactivated appropriately. So I guess I need to force the
workbook to open with one sheet active at all times. Is there a way I
can do that?

2. The second complication is as below. The workbook has three sheets.
We have taken care of the Sheet1 and Sheet2. But the third sheet will
be generated by collecting tables from the Sheet2. Now in Sheet3 I
should be able to have the menu appear. Right now it appears. Also it
appears with menu settings for the Sheet1 or Sheet2, depending on the
sheet that we were on before coming to the Sheet3.

Right now I have a Sub with name GenerateCodeSheet() as a module
that generates the Sheet3. I have created the Sub like
Worksheet_Activate() as part of the same module. I call
Worksheet_Activate() at the end of the GenerateCodeSheet(). But this
way I can have the Worksheet_Activate() run only when I create it. But
after that if I click on Sheet1 or Sheet2 and then come back to Sheet3,
the menu settings will be of either Sheet1 or Sheet2 respectively. I
guess I need to have the GenerateCodeSheet() modified in such a way
that it will write the Worksheet_Activate() code to the Sheet3 window.
Any suggestions or solutions.

Thanks in advance for everyone who help me.

Shishi

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default How can enable and disable menuitems based on the type of sheet.

Hi all,

I have solved the first problem by changing the code as below.

Private Sub Workbook_Open()
Call MakeMenu
Sheets("Sheet1").Activate
End Sub

But still trying to figure out a solution for the second problem.

Thanks,
shishi

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default How can enable and disable menuitems based on the type of shee

See Chip Pearson's notes on coding to the Visual Basic Editor. This should
allow you to add the worksheet activate/deactivate events to the newly
created sheet.

Make sure you set a reference to Microsoft Visual Basic for Applications
Extensibility (paragraph 5) and check your VB security (paragraph 7).

There is a section title "Creating an Event Procedure" which is what you
want to do.

www.cpearson.com/excel/vbe.htm

Regards
Rowan

"shishi" wrote:

Hi all,

I have solved the first problem by changing the code as below.

Private Sub Workbook_Open()
Call MakeMenu
Sheets("Sheet1").Activate
End Sub

But still trying to figure out a solution for the second problem.

Thanks,
shishi




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default How can enable and disable menuitems based on the type of shee

Rowan,

Thank you very much for your reply. I truly appreciate your help.

shishi

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
enable/disable button based on cell value Shoney Excel Discussion (Misc queries) 3 January 9th 08 07:34 PM
Conditional formatting based on decision to enable/disable macros? zenahs Excel Discussion (Misc queries) 1 November 15th 05 07:40 PM
Enable/Disable Macros Ben Schaum Excel Discussion (Misc queries) 1 January 21st 05 03:42 PM
Enable/Disable Button surplusbc[_6_] Excel Programming 1 February 1st 04 09:53 PM
macro disable and enable. paul[_12_] Excel Programming 1 January 9th 04 01:29 PM


All times are GMT +1. The time now is 03:31 PM.

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"