Warning message before closing Excel

Solved
Good evening,

I would like Excel (version 1997-2003) to prompt me before exiting by clicking the cross, asking if I have properly entered the date and the name of the person responsible for updating the file on the home sheet.

Message box: "Have you entered your name and the date of the last update on the home sheet? Thank you."

Thank you very much.
Configuration: Windows XP Internet Explorer 6.0

3 answers

  • Votes
  • Date
  • Descending date
  1. Hello,

    You open your Visual Basic Editor, either through the visual basic bar or by right-clicking on a sheet tab in the VBAProject, you will find ThisWorkbook, you paste the code below

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Msg = "Have you entered" & vbCrLf & "" & vbCrLf & " your name and the date of the last update on the home sheet thank you"
    StyleBoîteDialogue = vbOKOnly + vbQuestion
    Title = "Before closing this file,"
    response = MsgBox(Msg, StyleBoîteDialogue, Title)
    End Sub

    We'll talk about it tomorrow

    See you later
    1. Hello Mike,

      Okay, I'll check that at work and keep you posted!
      Thanks a lot!
    2. Good evening and thank you very much Mike-31!

      You solved the problem for me and it’s perfect!
      I have a small question, although I don't want to take advantage, could you explain the role of the following characters that you included in the macro?

      "& vbCrLf & "" & vbCrLf &"

      Thank you
      very much and see you soon...
      Dan.
  2. Yes, there are books, but to advise you, I'm a bit overwhelmed. To start, go to a large store or FNAC and select books based on your current knowledge in order to understand the more technical codes and not get lost.

    Then be curious, sign up for a forum and follow various conversations at your level and practice on your PC.

    One piece of advice: don't try to rush things, Excel has a monstrous amount of possibilities.

    Good luck, see you!
    1. That's good, this kind of little exchange has solved my problem too! And well done for the advice.
  3. Hi,

    this is the code to create an additional line in your msgbox to avoid having overly large msgboxes and to facilitate reading

    below your text is on three lines
    Msg = "Have you written" & vbCrLf & "" & vbCrLf & " your name and the date of the last update

    below your text is on two lines
    Msg = "Have you written" & vbCrLf & " your name and the date of the last update on the home sheet thank you"

    below your text is on one line
    Msg = "Have you written your name and the date of the last update on the home sheet thank you"

    See you later!
    1. Ok, I understand that I'm not equipped to guess all that!
      Last question, is there a dictionary that discusses the main VBA codes for Excel 1997?
      Have a good evening.
      Dan.