Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
KandK
 
Posts: n/a
Default STOP WORKBOOK CLOSING

Is there anyway of stopping someone closing a workbook unintentionally by
maybe having to enter a password or a warning coming up asking are you sure
you want to close. Anything to deter people from closing it. Can someone
please help.
  #2   Report Post  
Posted to microsoft.public.excel.misc
Tristan
 
Posts: n/a
Default STOP WORKBOOK CLOSING


Hi KandK

What you're asking is possible. Don't know how versed you are in Excel
programming so Janet adn Joh instuctions follow:

1. Open your file
2. Press Alt+F11. This will open the Visual Basic window
3. In the top left-hand window double click on "Worksheet"
4. Probably a large white window has just appeared (if it hasn't go to
View - Code (F7)
5. Copy and paste the code below into the big white window.
6. Close the window to get back to the Excel worksheet.
7. Try and close it and hopefully a dialogue box will pop up asking if
you're sure.

//////////////////////////////////////////////////////////////////////////////////
'Copy and Paste all the below
'
Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Dim Answer As VbMsgBoxResult

Cancel = True
Answer = MsgBox("Are you sure?", vbOKCancel, "Insert appropriate
text here")
If Not Answer = vbCancel Then
Cancel = False
End If

End Sub


--
Tristan
------------------------------------------------------------------------
Tristan's Profile: http://www.excelforum.com/member.php...o&userid=34061
View this thread: http://www.excelforum.com/showthread...hreadid=539033

  #3   Report Post  
Posted to microsoft.public.excel.misc
KandK
 
Posts: n/a
Default STOP WORKBOOK CLOSING

Thanks Tristan that worked excellently. I was wondering if it is possible to
actually password protect BeforeClose. I have looked at the Visual Basic help
but as I am new to using it I am afraid it is a bit over my head.
Once again thanks so much for the help.

"Tristan" wrote:


Hi KandK

What you're asking is possible. Don't know how versed you are in Excel
programming so Janet adn Joh instuctions follow:

1. Open your file
2. Press Alt+F11. This will open the Visual Basic window
3. In the top left-hand window double click on "Worksheet"
4. Probably a large white window has just appeared (if it hasn't go to
View - Code (F7)
5. Copy and paste the code below into the big white window.
6. Close the window to get back to the Excel worksheet.
7. Try and close it and hopefully a dialogue box will pop up asking if
you're sure.

//////////////////////////////////////////////////////////////////////////////////
'Copy and Paste all the below
'
Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Dim Answer As VbMsgBoxResult

Cancel = True
Answer = MsgBox("Are you sure?", vbOKCancel, "Insert appropriate
text here")
If Not Answer = vbCancel Then
Cancel = False
End If

End Sub


--
Tristan
------------------------------------------------------------------------
Tristan's Profile: http://www.excelforum.com/member.php...o&userid=34061
View this thread: http://www.excelforum.com/showthread...hreadid=539033


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
Stop the prompt to save when closing workbooks Rebecca Potter Excel Discussion (Misc queries) 1 December 2nd 05 11:00 AM
Protect Workbook vs Worksheet?? Dan B Excel Worksheet Functions 3 November 7th 05 10:02 PM
Prevent Excel closing all workbook instances when clicking on "X" Deeptech-NM Excel Discussion (Misc queries) 8 July 4th 05 02:36 PM
How to hyperlink from a workbook to sheets in another workbook? MJOHNSON Excel Worksheet Functions 0 February 17th 05 09:31 PM
How do I stop Excel from closing the open file each time I open a. Welsin Setting up and Configuration of Excel 3 January 9th 05 12:16 AM


All times are GMT +1. The time now is 11:33 AM.

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

About Us

"It's about Microsoft Excel"