PDA

View Full Version : [SOLVED] Command Button to save & close workbook



deano36
08-17-2005, 11:40 AM
Hello everyone -
Hope you are all doing well on this fine day. I am sure this is posted somewhere - however I am in a rush.
I would like to create a command button that will save & close a workbook. Nothing major - my brain is malfunctioning today. Yesterday was my birthday - so I have an excuse - a senior moment. :think:

gibbo1715
08-17-2005, 11:59 AM
in its simplest form


ThisWorkbook.save
Application.Quit

deano36
08-17-2005, 12:19 PM
Thanks very much - that was quite simple. However, I realized that this would not be enough. I am not very VBA-savvy. Here is what I really need done. I need to disable any other method of closing the workbook - except this one.

mdmackillop
08-17-2005, 12:36 PM
Try the following
In the Workbook module



Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = Not CheckClose
End Sub


In a Standard module



Public CheckClose As Boolean
Sub DoClose()
CheckClose = True
ThisWorkbook.Save
ThisWorkbook.Close
End Sub