Consulting

Results 1 to 5 of 5

Thread: Msgbox to open when excel closes.

  1. #1
    VBAX Regular
    Joined
    Sep 2004
    Posts
    32
    Location

    Msgbox to open when excel closes.

    Hello,

    I am after a small bit of VBA to help me with a problem. I would like a message box to appear on a spreadsheet when it closes that says "Have you updated the Spreadsheet" then a Yes No option. If the user clicks Yes it will fire a Macro. If they click no the spreadsheet will close as normal.

    is this simple to do?

    Many thanks

    Bacon

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Place this code in the ThisWorkbook Code Window:

    Option Explicit

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim Prompt          As String
    Dim Title           As String
    Dim MyResponse      As VbMsgBoxResult
        Prompt = "Have you updated the Spreadsheet"
        Title = "Insert Title Here"
        MyResponse = MsgBox(Prompt, vbYesNo + vbQuestion, Title)
        If MyResponse = vbYes Then
        Call Macro1
        End If
    End Sub

    Change Macro1 to the name of the macro you want to run if the user presses yes.

  3. #3
    VBAX Regular
    Joined
    Sep 2004
    Posts
    32
    Location
    works a treat

    Many thanks

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    Take Care

  5. #5
    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •