Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Closing a workbook by a button only

At a punt does it help to switch the two calls in the
cmdback procedure. So you set ControlClose before you
unload me?

Jase
-----Original Message-----
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



.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Closing a workbook by a button only

Hi Jase

I tried what you suggested which made sense.
Also, the code was in a bit of a state and I had a
BeforeSave setting the ControlClose to False which
probably didn't help.
Anyhow it works now!

Thanks very much
Libby
-----Original Message-----
At a punt does it help to switch the two calls in the
cmdback procedure. So you set ControlClose before you
unload me?

Jase
-----Original Message-----
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



.

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing a workbook N1KO Excel Discussion (Misc queries) 0 February 12th 09 03:51 PM
STOP WORKBOOK CLOSING KandK Excel Discussion (Misc queries) 2 May 5th 06 09:40 AM
Help with closing down a workbook?? Don Excel Worksheet Functions 1 May 9th 05 04:05 AM
prohibit closing a workbook Christophero Excel Discussion (Misc queries) 2 April 4th 05 05:54 PM
Closing a workbook with no alerts Antonio Atala Excel Programming 1 September 16th 03 04:32 AM


All times are GMT +1. The time now is 08:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"