View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Libby-xl97 Libby-xl97 is offline
external usenet poster
 
Posts: 1
Default Closing a workbook by a button only

Hi

I have a spreadsheet which is updated and saved by the
user clicking a button on the sheet and then responding to
a form. However, if the workbook is closed by using the x
then the updates are not made.

To counter this, I've disabled the x so that the workbook
can only be closed by following my intended route.

There are two buttons on the form, Close and Back. Close
closes the workbook and back unloads the form but keeps
the workbook open.

This is my code so far
This prevents the x from working when they open the
workbook, thus preventing the user from closing it.

Public ConTrolClose

Private Sub Workbook_Open()
ConTrolClose = True
End Sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)
Select Case ConTrolClose
Case True
Cancel = True 'cant close workbook
Case False
Cancel = False ' can close workbook
End Select
End Sub


After the user has clicked the button on the sheet, the
updates will be made the form will appear with the option
to go back to the sheet or close

Private Sub cmdClose_Click()
ConTrolClose = False
Application.Quit
End Sub

Private Sub cmdBack_Click()
Unload Me
ConTrolClose = True
End Sub

The problem occurs if the user clicks the Back button. For
some reason the x then closes the workbook, despite my
ConTrolClose being set to True.

Any ideas?

Libby