+ Reply to Thread
Results 1 to 10 of 10

Closing the workbook & saving automatically

Hybrid View

  1. #1
    Registered User
    Join Date
    06-08-2005
    Posts
    67

    Closing the workbook & saving automatically

    I have my Excel workbook open & have made changes. Now I close it and Excel prompts me if I want to save the changes. Is there a way to just close the workbook and automatically accept any changes without have the "Do you want to save changes" message appear?

    What about if it is opened in read-only mode? Typically the workbook will not save any changes unless you save it off as another file name. If there is a solution to my question above, can it be enabled only when the workbook is opened in edit mode, or will it not auto-save changes over the file because Excel knows it was opened in read-only mode?

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I don't think you can save changes in Read Only.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,493
    Once the workbook has been saved you can use this, it goes into the workbook module
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    ThisWorkbook.Saved = True
    
    
    End Sub
    You can set up the workbook to be read only in the tools options, and then use a password if you want to modify the workbook....
    Last edited by davesexcel; 01-25-2008 at 11:59 AM.

  4. #4
    Registered User
    Join Date
    06-08-2005
    Posts
    67
    Sorry...the above still displays the "Do you want to save your changes" message when I try to close the workbook.

    I tried using the same thisworkbook.saved = true

    in the auto_close macro, but it did not save any changes I made to the workbook.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try


    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        ThisWorkbook.Save    
    End Sub

  6. #6
    Registered User
    Join Date
    06-08-2005
    Posts
    67
    Still get the "Do you want to save your changes" message. If I add

    Application.DisplayAlerts = False
    to the workbookbeforeclose macro, I still get the message.

    Just noticed something...these macros are contained on my sheet object. Do they need to be on my workbook object instead?
    Last edited by VBA Noob; 01-25-2008 at 02:41 PM.

  7. #7
    Registered User
    Join Date
    06-08-2005
    Posts
    67
    Got it working mostly with...

    Private Sub Workbook_BeforeClose(cancel As Boolean)
    Application.DisplayAlerts = False
    ThisWorkbook.Save
    End Sub
    When opened in read-only mode, if someone tried to make a change, it closes without saving the changes.
    Last edited by VBA Noob; 01-25-2008 at 02:42 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