+ Reply to Thread
Results 1 to 8 of 8

disable red X but keep enable file - close working

  1. #1
    Registered User
    Join Date
    12-24-2008
    Location
    Oosterhout, the Netherlands
    Posts
    5

    disable red X but keep enable file - close working

    Hi

    I want to hide all toolbars and disable the red X upon opening of the spreadsheet, and to restore the main toolbars upon closing. That worked perfectly. (when I used the black code -see below)
    I added in the red code as i wanted to disable the red X as well to ensure that users will always close the EXCEL worksheet via a Macro button
    The Macro will save the spreadsheet and close the worksheet and the Private sub should restore the toolbars.

    Please Login or Register  to view this content.
    The problem with the red code (which I picked up in the link below) is that it fully disables to close the spreadsheet. Can anyone help to resolve this for me?
    http://www.ozgrid.com/forum/showthread.php?t=57334

    Thanks
    Rough

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    What about adding

    Please Login or Register  to view this content.
    as the last instruction before the close file instruction in your File Close macro?

    Rgds

  3. #3
    Registered User
    Join Date
    12-24-2008
    Location
    Oosterhout, the Netherlands
    Posts
    5
    Hi

    I have tried that with the following save and close macro:

    Please Login or Register  to view this content.
    But it does not work.
    Just to make sure we have the same picture: about what I am doing:
    The Personal Subs are directly behin "This Wokbook" and this Macro is "odule1"

    Any other ideas?
    thanks
    Rough

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Where did you get CloseMode? It's applicable to forms, not workbooks. If you're not using Option Explicit, then it's being created on the fly, and will therefore always be False.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    12-24-2008
    Location
    Oosterhout, the Netherlands
    Posts
    5
    Hi SHG

    I do not understand what you are trying to explain.
    I am not that familiar with VBA as yet. Just getting the hang of understanding the extras above recording a macro in EXCEL.

    I am not using a user form.
    I am / the user is, directly working in the EXCEL sheet. Everything that should not be used by the user, is protected and I want to avoid that they take of the protection manually. So therefor I hid all the toolbars. But I want them to close the EXCEL sheet via a Macro and not by exident via the red X.
    Therefor the code to disable the red X is fine, but as mentioned before it does not allow me to close the worksheet with the code anymore:
    Please Login or Register  to view this content.
    I do not understand what you mean with the Option Explicit, can you explain me a bit more, or help with adjusting the code?
    Thanks
    Rough

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    CloseMode is a variable. Where does it come from, where is it set?

    Option Explicit is a statement that tells the compiler that all variables must be explicitly declared; it gives a compile error if you try to use a variable that isn't declared.

    The code you got from Oz tested CloseMode when a form was being closed. It is passed to the BeforeClose event of a form as an argument; it is NOT passed as an argument to the BeforeClose event of a workbook, so it doesn't exist.

    Absent Option Explicit, the compiler just creates the variable when you use it, but it contains nothing.
    Last edited by shg; 12-24-2008 at 03:10 PM.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Rough,

    This macro will allow you to enable or disable Excel's close "X".
    Please Login or Register  to view this content.
    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time.
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    Calling the Macro
    The macro takes a single boolean argument (True or False). When True the close "X" is enabled, and when False the close "X" will be disabled. Here is an example...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  8. #8
    Registered User
    Join Date
    12-24-2008
    Location
    Oosterhout, the Netherlands
    Posts
    5

    Thumbs up

    Hi Leith Ross
    Thanks for your help.
    I have got it working
    Regards
    Rough
    (how do I put this thread to Solved?)
    Last edited by Rough; 12-28-2008 at 06:22 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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