+ Reply to Thread
Results 1 to 16 of 16

How to Prevent Save or Save As for Excel File by VBA

  1. #1
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Question How to Prevent Save or Save As for Excel File by VBA

    Guys,

    Any Ideas on How to build a macro and auto run on file start up that will prevent any user to Save or SaveAs.

    BR,

  2. #2
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: How to Prevent Save or Save As for Excel File by VBA

    Copy the code below to your "ThisWorkbook" in VBE

    Please Login or Register  to view this content.
    Obviously only works when Macros are enabled though

  3. #3
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: How to Prevent Save or Save As for Excel File by VBA

    some person opening the workbook, he will not run any macro. Will this run automatically and upon which event

  4. #4
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: How to Prevent Save or Save As for Excel File by VBA

    The first part will be when the user tries to save, the second will tell Excel the Workbook has been saved so you don't get the "Save changes" prompt when closing the book.

  5. #5
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: How to Prevent Save or Save As for Excel File by VBA

    it doesnt do anything I am able to make changes and save and close

  6. #6
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: How to Prevent Save or Save As for Excel File by VBA

    Well, that is odd... I've used that code for ages :-/

    What version of Excel are you using?

  7. #7
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: How to Prevent Save or Save As for Excel File by VBA

    can you tell me how to execute the code.

    I just opened a new module in the subject workbook, pasted your code and saved and closed the file then. I again opened the file and changed somethings and I was able to save it.

  8. #8
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: How to Prevent Save or Save As for Excel File by VBA

    excel 2010

  9. #9
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: How to Prevent Save or Save As for Excel File by VBA

    As I said in my original post, you need to put that code into "ThisWorkbook", you don't create a Module for it.

    From a fresh Workbook open up the VBE - In the Project Explorer you'll see Sheet1 (Sheet1) and directly under that "ThisWorkbook" - That is where the code should go.

  10. #10
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: How to Prevent Save or Save As for Excel File by VBA

    OKAY, I got it now. Sorry.

    Thanks, it works.

  11. #11
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: How to Prevent Save or Save As for Excel File by VBA

    No problem - Glad we got there in the end

  12. #12
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: How to Prevent Save or Save As for Excel File by VBA

    This code works only one time.

    When I close the workbook and open again, the Code is missing in ThisWorkbook - View Code

    And it is enables for edit and save changes.

    Please advise.

  13. #13
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: How to Prevent Save or Save As for Excel File by VBA

    You need to have Saved the code into the Workbook for it to stay...

    Either Disable Macros in Security, add the code, save and re enable them, or from the VBE - After Pasting in the code to the ThisWorkbook module go to the Immediate Window and type;

    Please Login or Register  to view this content.
    And then save the Workbook. Close it down, reopen it and saving should be disabled from that point.

    But you won't be able to save it after you've added things to it without over riding it.

    I've attached an example of it saved within a Workbook for you.
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: How to Prevent Save or Save As for Excel File by VBA

    Do have any codes to prevent:
    - Cut
    - Copy
    - Paste
    - Drag and Drop
    - Move/Copy Sheet

    Do you need me to open a new thread for this question ?

  15. #15
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: How to Prevent Save or Save As for Excel File by VBA

    Yes, start a new thread as they are different questions.

  16. #16
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: How to Prevent Save or Save As for Excel File by VBA

    I did so, but there seems no solution on that thread,

    Please have a look.

    https://www.excelforum.com/excel-gen...ove-sheet.html

+ 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. [SOLVED] If file already open, how to prevent read-only copies from attempting to save
    By indub in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-27-2017, 12:05 PM
  2. [SOLVED] Disable save and prevent "Do you want to save" message from prompting for read-only file
    By hcyeap in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-12-2014, 12:29 AM
  3. Prevent Save, enable SaveAs with default file name
    By Dora in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-05-2013, 01:35 AM
  4. Replies: 1
    Last Post: 09-05-2013, 02:39 PM
  5. Prevent file save until conditions are met
    By Varun_21 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-30-2010, 10:07 PM
  6. Replies: 2
    Last Post: 03-23-2009, 10:16 AM
  7. [SOLVED] 'document not saved' for 'save' or 'save as' an EXCEL file
    By Judy Chuang in forum Excel General
    Replies: 1
    Last Post: 07-11-2005, 06:05 PM

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