+ Reply to Thread
Results 1 to 16 of 16

Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

  1. #1
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    Hi,

    I've been playing with some code to try and prevent a user from carrying out certain tasks from a custom menu when the work book is opened read only - basically to prevent them wasting time working on things then realising they can't save it as it's read only. The menu is created only when a specific sheet is active, and deleted when not.

    However I can't quite get it to work, any ideas what I'm doing wrong? Sure it's something silly...


    Please Login or Register  to view this content.
    Any help appreciated.

    Thanks, TC

  2. #2
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    Should probably add that I don't get an error message or anything but that the menu item is not greyed out and still triggers the "NewCase" code...

  3. #3
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    Anyone got any thoughts on this?

  4. #4
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    I know it's Friday, but just on the off chance - any ideas what I'm doing wrong here???

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    if you get no error it would seem the active workbook is not read only. when does this code run?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    When its opened 'read-only' does it give them an option at the top to enable editing?

    Can the userform be opened modeless so if necessary they can switch to the workbook and enable editing?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  7. #7
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    Wow, I'm impressed - no shirking on a Friday

    JosephP, I believe the Active Workbook is read only. It's the only one open and the Window title is showing as the file name followed by [Read Only]. The code to add the menu (as above) is triggered by the WorkSheet Activate event in the relevant sheet and run from Module 1. This is so that the Menu is only added for the user to access when they have the right workbook / worksheet selected. It's deleted on the deactivate event.

    XeRo Solus - I'm not sure what you mean by enable editing? I have selected Enable Macros and the sheet can be edited - but cannot be saved - is this not true read only? I would like certain users to have the modify password and be able to edit and save the workbook, while other users would not have the password and open as read only just to view the information.
    Again not sure about modeless - the Show Modal property is set to true but I don't see how the user would access the form any other way that through the menu - which is what I'm trying to prevent them from doing.

    I'm trying to avoid a situation where a user would go in as read only - get distracted - forget they went in as read only - carry out a load of work - then go to save it only to find that they cannot. Would make me pretty angry...

    Does this make any sense at all?

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    can you put a breakpoint in the code and see what's happening?

  9. #9
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    Okay, this is really weird.

    I opened the workbook and stuck a pause break in the code listed above. Then to trigger the code selected another sheet and when back to the 'Tracker' sheet. This triggered the code as expected and hey presto the menu item is greyed out. Why was it not greyed out when the menu was first created??? Would it not check it was read only then?

    Anyway so I came out of the work book and opened it as read write, but the menu item is still greyed out. If i flick between sheets it rund through the code and then it's no longer greyed out.

    To summarise, it looks likt the first time the AddMenu code it run it's not triggering that bit of code - or doesn;t know if it's read only or not at that point? Really can't work out the logic...

    Does this make any sense to you or is it best just to put a work around in so that it opens on another sheet then activates the tracker sheet. Seems a bit cluncky....

  10. #10
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    I think maybe if you could redact any sensitive information from your workbook and attach it to your post it might help to get to the bottom of it.

  11. #11
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    I suspect you need to call your code from your workbook_open event and workbook_beforeclose too to ensure that the menu is reset when you first close/open the workbook.

  12. #12
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    Apologies for the delay in responding - been manic at work recently.

    I've done as you suggested Josie and called the sub to add the menu from the workbook open event and delete from the workbook close event - in addition to the activate and deactivate code. Everything appears to run fine now.

    Still makes no sense to me that on opening the menu was being added but for some reason wasn't checking if if read only / read write and somehow just carried over the status from the last time it was open. One of those VBA peculiarities I guess? I would submit a trimmed down version of the workbook - but I can't upload anything from work so i'll have to write something from scratch at home - when I have some spare time perhaps. For now though this has fixed my problem.

    Thanks Josie & Solus.

  13. #13
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    I don't think it was being added-it wasn't being removed when the workbook was last closed

  14. #14
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    Just went back and checked on an older version and you are right! Feel like such a noob!
    I presumed that activate and deactivate wolud happen as part of opening and closing the workbook.

    One last question then, is it better to 're-build' the menu on the activate event and then delete it on deactivate each time - or now that i have it as part of open and close, would it be better to 'hide / disable' it when the worksheet is not active?

    Sorry and thanks again.

  15. #15
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    I don't think it makes a lot of difference but I would delete and rebuild for safety

  16. #16
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Trying to 'Grey Out' menu items on Custom Menu if Workbook is ReadOnly

    Okay, that's great. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. creating new custom menu items
    By tryer in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-03-2010, 10:48 AM
  2. Replies: 3
    Last Post: 06-27-2006, 08:50 AM
  3. Create/Remove Custom Menu Items from Add-in
    By Michael Malinsky in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-27-2005, 02:04 AM
  4. [SOLVED] coping custom menu items
    By bobbyvt in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-08-2005, 11:06 AM
  5. [SOLVED] Menu items added with menu item editor in older versions
    By Michael Hoffmann in forum Excel General
    Replies: 2
    Last Post: 01-07-2005, 10:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1