+ Reply to Thread
Results 1 to 8 of 8

Need Help changing how the excel window closes to use a macro instead (the red X)

  1. #1
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Unhappy Need Help changing how the excel window closes to use a macro instead (the red X)

    I've been looking around trying to figure out how to change what happens when the X in the Excel window is clicked. So far I've found the coding for disabling the X, but this isn't what I really would like to do. I'm trying to make it so that when it is clicked/selected that a macro I generated to close save the workbook and close excel is run instead. Any help, even pointing me toward a resource, would be appreciated. Thanks in advance
    Last edited by LoneWolf3574; 12-08-2012 at 05:40 AM. Reason: Title change

  2. #2
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Re: Need Help to changing how the excel window closes to use a macro instead (the red X)

    I've figured out how to disable the excel title bar X from the moment I open the workbook, but still would love some help on changing how the excel workbook window X functions to run a macro instead. Thanks

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Need Help to changing how the excel window closes to use a macro instead (the red X)

    Hello LoneWolf3574,

    You don't show us what your Code looks like, so assuming you have it set up right, you could add these line at the bottom of your Code.

    Please Login or Register  to view this content.
    Hope that helps.

    Also see the "Please consider" note at the bottom of this post.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Forum Contributor
    Join Date
    08-23-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Need Help to changing how the excel window closes to use a macro instead (the red X)

    Hi,

    Not sure if this is what you need, but check Workbook_BeforeClose events.

  5. #5
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: Need Help to changing how the excel window closes to use a macro instead (the red X)

    Hi -

    In your VBA Project Window, double click in Thisworkbook from the left, and on the right side, select workbook from the general dropdown and on the declations dropdown, you can see various events for the workbook, look for beforeclose event which I think you're looking for.

    Regards,
    Event

  6. #6
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Re: Need Help to changing how the excel window closes to use a macro instead (the red X)

    Ok, I think I'm getting a clue now here. So how do I get this macro to be run in ThisWorkbook after getting the beforeclose event in the dropdown? I've included my disable for the titlebar and what I've got in the ThisWorkbook so far for activating it.

    Please Login or Register  to view this content.
    For disabling the title bar X (excel program) I found and modified the following

    Please Login or Register  to view this content.
    and use the following code in the "ThisWorkbook" object

    Please Login or Register  to view this content.
    Last edited by LoneWolf3574; 12-08-2012 at 05:38 AM. Reason: The dim bulb is starting to brighten

  7. #7
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Re: Need Help changing how the excel window closes to use a macro instead (the red X)

    Ah ha, got it finally. I have placed the following coding in my ThisWorkbook object module

    Please Login or Register  to view this content.
    The coding in RED solved the issue and the messagebox tells the individual to quit trying to close it that way. Perfecto Mundo

  8. #8
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Re: Need Help changing how the excel window closes to use a macro instead (the red X)

    Something I'd like to add, I kept getting an error (don't remember what it was exactly off the top of my head) when I clicked my "Save & Close" button. It kept highlighting the Selection.Locked line as the culprit, so what I ended up doing was deleting these and similar lines within my coding -

    Please Login or Register  to view this content.
    And adding the following instead -

    Please Login or Register  to view this content.
    Seeing as all but a few select cells on all sheets are locked for change and formula viewing, plus those cells can't be changed with a UserForm up, I didn't need the coding in question.

+ 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