The problem is that your "Activeworkbook.Close" command is calling this event!
You have two choices:
Use:
Application.enableevents = false
Activeworkbook.close savechanges:=False
Paul
-----------------------------------------
"Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can." - John Wesley
-----------------------------------------
________________________________
From: Torstein Johnsen <sejohnse@yahoo.no>
To: "ExcelVBA@yahoogroups.com" <ExcelVBA@yahoogroups.com>
Sent: Fri, June 7, 2013 1:26:14 PM
Subject: [ExcelVBA] Before close procedure
I have put
this procedure in This workbook section.
It starts
to run when user try to close workbook, and if he doesn't type the correct
password, the closure
is cancelled and msgbook ("No closing").
So far, so
good!
But if the
user types the correct password, the same inputbox is shown twice before the
workbook is closed.
Why? And
can someone help me with a fix?
---------------
'Private
Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayAlerts
= False
svar =
InputBox("password!")
If
UCase(svar) = "HNN" Then
ActiveWorkbook.Close
SaveChanges:=False
Else
Cancel =
True
MsgBox
("no closing!")
End If
End
End Sub
[Non-text portions of this message have been removed]
[Non-text portions of this message have been removed]
Reply via web post | Reply to sender | Reply to group | Start a New Topic | Messages in this topic (9) |
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.
----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA
----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com
----------------------------------
Tidak ada komentar:
Posting Komentar