You are here:

Excel/Userform beforeclose closes without saving.


Hi dave,

I just used the code taken from for workbook open user form and it works perfectly as i needed.Likewise i just modified it a bit as you had suggested for beforeclose and it also works fine.But what happens is when i close excel the pop up appears and when i close the userform it quits from excel without option for saving.How to modify the code to ask enduser for saving the workbook finally?

The code seen below is entered in workbook module.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
With UserForm2

       .StartUpPosition = 0

       .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)

       .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)


   End With
End Sub



You should not be able to close the userform, it closes by itself.

It asks me if I want to save changes when the userform closes. Maybe your workbook is already saved when you click the close Button.

You can add to the unload routine in the regular module to make sure the workbook saves.

Sub UnloadScreen()
   Unload UserForm1
End Sub
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Dave Morrison


I can answer most excel questions My Website is


I have been working with spreadsheets since 1991. I am a self-trained excel developer since 2005.

My website

Business admin. U of R.

Awards and Honors
Microsoft Excel MVP 2011-2012

©2016 All rights reserved.