+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    04-30-2009
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2003
    Posts
    1

    Exclamation Display yes/no msx box on exiting Excel

    Hello,

    I am very new to VBA and struggling with a code to do a simple job. I am sure the solution is something very easy, any help on this will be appreciated..

    I have developed this spreadsheet in my company which will be updated by more than 3 persons on an ongoing basis. One of the sheets in this workbook contains a simple table where the user documents all changes he has made in his session. The idea is for a new user to know in one glance the last 10 changes made to the workbook. So i would like a msg box to appear when a user clicks on X to close excel once his session is over. This msg box should be a yes no msg box and ask something like "Have you filled in the changes made table on the first sheet?" If the asnwer is Yes then save and close and if no, then go to the first sheet to cell B2.

    Any ideas??

  2. #2
    Forum Guru mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,984

    Re: Display yes/no msx box on exiting Excel

    This will only work if Macros are enabled

    Change Sheet1 to suit

    'These instructions pre typed & are worded to cater for the novice programmer

    'To install macro to correct location

    'Copy this macro
    'GoTo Excel
    'Open VB Editor by pressing Alt + F11
    'Just below the menus & toolbars on the left you should see Project - VbaProject window
    'In this window you will see ThisWorkbook
    'double click on ThisWorkbook - opens ThisWorkbook module sheet
    'Paste macro code into big window on right

    Code:
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
       If MsgBox("Have you filled in the changes made table on the first sheet?", vbYesNo + vbDefaultButton2 + vbQuestion) = vbNo Then
          Cancel = True
          Sheets("Sheet1").Activate
          Range("b2").Select
          Exit Sub
       End If
    End Sub
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

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.2.0