+ Reply to Thread
Results 1 to 8 of 8

Force "Save As" in Prompt Before Close - X Button

  1. #1
    Registered User
    Join Date
    05-30-2013
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2010
    Posts
    12

    Question Force "Save As" in Prompt Before Close - X Button

    Hi everyone,

    I need a macro that will replace the function SAVE in close prompt dialog ("Do you want to save the changes you made to book?"). It's possible to replace the function to SAVE AS, instead of SAVE (when a user modify a existing spreadsheet an then close it in X button, the file will be overwritten, and we want to change it). If isn't possible, can i disable the button SAVE from this prompt and keept the others (DON'T SAVE and CANCEL)?

    And:

    It's possible to open documents of certain paths as read-only? (example: if a documents is opened from My Documents and Desktop it will be read-only, but from others locations not).

    Thank you in advance

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Force "Save As" in Prompt Before Close - X Button

    For the saveas issue try:
    Please Login or Register  to view this content.
    For the other one: I don't see a possibility to tell the excel application to check the file location of a file you double clicked to open and set readOnly appropriately in VBA. Maybe somebody else has an idea?
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    05-30-2013
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Force "Save As" in Prompt Before Close - X Button

    Really thank you tehneXus. That was exactly what I needed.

    But i found a issue. I created a XLAM addin, and added to THIS WORKBOOK (not to a module). When I close the spreadsheet (saving or not, the application remains opened (the XLAM addin - Want to save your change to Book1.XLAM to a File).
    Then a I try to close it and the the save prompt is shown again.

    If I choose YES, I get a error: Nr.:91 Object variable or With block variable not set.

    If a choose NO, I got: N.:1004. Unable to get the Show property of the Dialog class.

    I replaced ActiveWorkbook to ThisWorkbook, and the error was gone, but if I choose NO in the SAVE AS prompt, i get the SAVE prompt again (and then, can overwrite the file).

  4. #4
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Force "Save As" in Prompt Before Close - X Button

    HI,

    I got it to work in an add-in but didn't found a solution to quit the application properly...

    Add-In "ThisWorkbook" module
    Please Login or Register  to view this content.
    Add-In ClassModule called: "clsWbEvents"
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Force "Save As" in Prompt Before Close - X Button

    For the other issue where a file from a certain folder should be opened as readyonly paste this into
    Add-In ClassModule called: "clsWbEvents"
    Please Login or Register  to view this content.
    Where every file that has "support" in the path will be reopened readonly

    As far as I can say maybe you don't need the beforeclose anymore as you cannot overwrite the file anyway then, and the application quit problem would be solved.

  6. #6
    Registered User
    Join Date
    05-30-2013
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Force "Save As" in Prompt Before Close - X Button

    Quote Originally Posted by tehneXus View Post
    HI,

    I got it to work in an add-in but didn't found a solution to quit the application properly...

    Add-In "ThisWorkbook" module
    Please Login or Register  to view this content.
    Add-In ClassModule called: "clsWbEvents"
    Please Login or Register  to view this content.
    Quote Originally Posted by tehneXus View Post
    HI,

    I got it to work in an add-in but didn't found a solution to quit the application properly...

    Add-In "ThisWorkbook" module
    Please Login or Register  to view this content.
    Add-In ClassModule called: "clsWbEvents"
    Please Login or Register  to view this content.
    Thank you again tehneXus. It worked very well. When I close the spreadsheet, the application remain opened, but without the error that I mentioned before. In this case, I can manually close the application after closing the spreadsheet.
    One last question: if I change the workbook references in the code to Document, is there possible to create a Word template, with this same code? (sorry for asking it in a Excel forum)

  7. #7
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Force "Save As" in Prompt Before Close - X Button

    One last question: if I change the workbook references in the code to Document, is there possible to create a Word template, with this same code? (sorry for asking it in a Excel forum)
    I have no clue when it's about Word VBA. You can try something similar based on that code.

  8. #8
    Registered User
    Join Date
    05-30-2013
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Force "Save As" in Prompt Before Close - X Button

    I'll try it.
    Thank you.

+ 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