+ Reply to Thread
Results 1 to 4 of 4

VBA YesNo Question BeforeSave

Hybrid View

  1. #1
    Registered User
    Join Date
    08-10-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    16

    VBA YesNo Question BeforeSave

    Hello,
    I am definitely NOT a programmer - but dabble and am having great trouble doing probably something simple.

    I want to ask a yes/no question before saving a workbook - "Have you updated the Last Updated date if needed?". If the answer is yes - save as normal; if the answer if no, cancel save.

    Any help would be MUCH appreciated!

    Thanks!
    Lisa

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA YesNo Question BeforeSave

    Lisa,

    Welcome to the forum!
    This code goes in the ThisWorkbook code module:
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
        
        Dim UserResponse As VbMsgBoxResult
        
        UserResponse = MsgBox(Title:="Last Updated Date", _
                              Buttons:=vbYesNo + vbQuestion, _
                              Prompt:="Have you updated the Last Updated date if needed?")
        
        If UserResponse = vbNo Then Cancel = True
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    08-10-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: VBA YesNo Question BeforeSave

    THANK YOU!!! Worked perfectly!!! I will remember to ask quickly next time instead of being so stubborn and trying to figure it out myself (... 4 hours later!).

    Thanks!
    Lisa

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA YesNo Question BeforeSave

    You're very welcome

    If that takes care of your need, please mark this thread as solved.
    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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