+ Reply to Thread
Results 1 to 8 of 8

Restricting close workbook until Saved in excel macro

  1. #1
    Registered User
    Join Date
    07-13-2013
    Location
    Austin
    MS-Off Ver
    Excel 2007
    Posts
    30

    Restricting close workbook until Saved in excel macro

    Hi All,

    I have created a workbook with multiple mandatory fields within it. What i wish is that all these fields must be filled before the workbook can be closed. For this i've tried 2 cases:-

    Case 1: Using BeforeClose event in Macro

    Problem with this is that user can leave the mandatory field blank and save it. Although he wont be able to close, but if he copies this saved workbook (by going to its location) to some other location(say) , he can use that copy as the original one.

    Now you would think, why wouold he do that. Answer is i dont want to leave any loophole in this.


    Case 2: Using BeforeSave event

    Problem with this is that when a i try to close the sheet with some mandatory field blank, it will prompt me "Do you need to save the changes,etc" . If i click Yes, it will prompt (created by me) to fill the mandatory field , and then close. And the field would be blank, next time we open it.


    So, How can i restrict the close until all the mandatory fields are filled and saved??


    Appreciate your help.

    Thanks
    Last edited by Scofield24; 02-06-2014 at 08:18 AM.

  2. #2
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Restricting close workbook until Saved in excel macro

    Hi,
    see if it helps you, I use it for a small project and it works fine!
    http://www.vbaexpress.com/kb/getarticle.php?kb_id=587
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  3. #3
    Registered User
    Join Date
    07-13-2013
    Location
    Austin
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Restricting close workbook until Saved in excel macro

    Hi John55,

    Thanks for your help. But sadly the example given by you has the same issue being faced by me as specified in case 1 above. If i blank out a mandatory field and save it, it gets saved. So, while the workbook is still open , if i copy the file (by going to its location) to some other location(say) , i can use that copy as the original one with that particular field still blank.

    Attaching the xls sheet justifying my point, for your rfeference


    Do you know of something else that i can try?

    Appreciate you helping me anyhow.

    Cheers!!
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Restricting close workbook until Saved in excel macro

    you can try the same code in
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-13-2013
    Location
    Austin
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Restricting close workbook until Saved in excel macro

    Hi John,

    I've already tried that. Plz refer to case 2 in my original question.

    Case 2: Using BeforeSave event

    Problem with this is that when a i try to close the sheet with some mandatory field blank, it will prompt me "Do you need to save the changes,etc" . If i click Yes, it will prompt (created by me) to fill the mandatory field , and then close. And the field would be blank, next time we open it.
    That too is not meeting my requirement.

  6. #6
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Restricting close workbook until Saved in excel macro

    Hi Scotfield,

    I am sorry! ...

  7. #7
    Registered User
    Join Date
    07-13-2013
    Location
    Austin
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Restricting close workbook until Saved in excel macro

    oh its ok... No need to apologize...

    Thanks for your help anyway

  8. #8
    Registered User
    Join Date
    07-13-2013
    Location
    Austin
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Restricting close workbook until Saved in excel macro

    Hi,

    I have posted this question at mrexcel.com also, since i wasnt able to get a solution here yet.

    http://www.mrexcel.com/forum/excel-q...ml#post3717851

    Thanks
    Scofield

+ 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. Look for and Open saved workbook retrieve information into new WB then close them
    By Aeneren in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-27-2012, 10:42 PM
  2. Excel crashes when macro gets workbook to close
    By Julesdude in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-24-2011, 09:50 AM
  3. Macro to close down word and re-open a previously saved document
    By snoopy1461 in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2011, 09:59 AM
  4. Save an open workbook, then open template workbook and close the saved workbook
    By ondvirg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2009, 10:20 PM
  5. running macro on close of workbook/excel
    By neowok in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-17-2005, 10:36 AM

Tags for this Thread

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