+ Reply to Thread
Results 1 to 8 of 8

avoid save file

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-20-2007
    MS-Off Ver
    2016, 365
    Posts
    127

    avoid save file

    Hi All.
    I would like to avoid user to SAVE or SAVE AS file. In my macro I used code to disable SAVE and SAVE AS from FILE menu. But how to avoid to save file if user use CTRL+S command to save file?
    Thanks.
    Last edited by eugz; 04-30-2009 at 12:18 PM.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,446

    Re: avoid save file

    In "ThisWorksheet" use the following code

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Cancel = True
    End Sub
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: avoid save file

    You might add
    Me.Saved = True
    to that so the user doesn't keep getting prompted to save on exit.

    And as a courtesy, also add something to tell the user what's going on:
    MsgBox "No saving allowed!"
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor
    Join Date
    07-20-2007
    MS-Off Ver
    2016, 365
    Posts
    127

    Re: avoid save file

    Thanks Dave. It is works. But I'm thinking user will confused when will try close file and get message: "Do you want to save the changes you made "filename.xls"?" User try to click YES button and message will on screen. How to avoid save file and avoid pop up message also?
    Thanks.

  5. #5
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,446

    Re: avoid save file

    You'll need to incorperate

    Application.DisplayAlerts = False
    into your code to avoid the warning when closing.

  6. #6
    Forum Contributor
    Join Date
    07-20-2007
    MS-Off Ver
    2016, 365
    Posts
    127

    Re: avoid save file

    I insert this code to ThisWorkbook
    Private Sub Workbook_Close()
        Application.DisplayAlerts = False
    End Sub
    But message still pop up. What I did wrong?
    Thanks.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: avoid save file

    There is no Close event
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        Me.Saved = True
    End Sub

  8. #8
    Forum Contributor
    Join Date
    07-20-2007
    MS-Off Ver
    2016, 365
    Posts
    127

    Re: avoid save file

    Thanks a lot everyone. It is exactly what I want to do.

+ 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