close

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.


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 quot;Worksheetquot;
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(quot;Are you sure?quot;, vbOKCancel, quot;Insert appropriate
text herequot;)
If Not Answer = vbCancel Then
Cancel = False
End If

End Sub--
Tristan
------------------------------------------------------------------------
Tristan's Profile: www.excelforum.com/member.php...oamp;userid=34061
View this thread: www.excelforum.com/showthread...hreadid=539033Thanks 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.

quot;Tristanquot; wrote:

gt;
gt; Hi KandK
gt;
gt; What you're asking is possible. Don't know how versed you are in Excel
gt; programming so Janet adn Joh instuctions follow:
gt;
gt; 1. Open your file
gt; 2. Press Alt F11. This will open the Visual Basic window
gt; 3. In the top left-hand window double click on quot;Worksheetquot;
gt; 4. Probably a large white window has just appeared (if it hasn't go to
gt; View - Code (F7)
gt; 5. Copy and paste the code below into the big white window.
gt; 6. Close the window to get back to the Excel worksheet.
gt; 7. Try and close it and hopefully a dialogue box will pop up asking if
gt; you're sure.
gt;
gt; //////////////////////////////////////////////////////////////////////////////////
gt; 'Copy and Paste all the below
gt; '
gt; Option Explicit
gt;
gt; Private Sub Workbook_BeforeClose(Cancel As Boolean)
gt;
gt; Dim Answer As VbMsgBoxResult
gt;
gt; Cancel = True
gt; Answer = MsgBox(quot;Are you sure?quot;, vbOKCancel, quot;Insert appropriate
gt; text herequot;)
gt; If Not Answer = vbCancel Then
gt; Cancel = False
gt; End If
gt;
gt; End Sub
gt;
gt;
gt; --
gt; Tristan
gt; ------------------------------------------------------------------------
gt; Tristan's Profile: www.excelforum.com/member.php...oamp;userid=34061
gt; View this thread: www.excelforum.com/showthread...hreadid=539033
gt;
gt;

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()