السلام عليكم ورحمة الله وبركاته
لمستك الفنية كان لها أثر كبير في نجاح الكود..فقد أضفت ذلك السطر في كود فتح الملف أيضا مثلما أضفته عند الغلق. فتم النجاح والحمد لله .
ربنا يغلق لك أبواب جهنم .. ويفتح لك أبواب الجنة.
أرجو مراجعة الكود للمرة النهائية لتقدمه للزملاء مشاركة مني
وجزاكم الله خيرا.
' In the name of ALLAH
Option Explicit
Const ApplicationTitle1 = "Officena"
Const ApplicationTitle2 = "OFFICENA"
Private BinNormalExit As Boolean
Private Sub Workbook_Beforeclose(Cansel As Boolean)
ActiveWorkbook.Save
If BinNormalExit = True Then
MsgBox "Remmber to back up yourwork " _
& "this application", vbExclamation, ApplicationTitle1
End If
End Sub
Private Sub Workbook_Open()
Dim StrCorrectPassword1 As String
Dim StrCorrectPassword2 As String
Dim StrUserPassword As String
Dim IntAttempts As Integer
Dim x As String
StrCorrectPassword1 = "ESSAM"
StrCorrectPassword2 = "AHMED"
StrUserPassword = InputBox("Enter Password", _
ApplicationTitle1)
IntAttempts = 1
Do Until StrUserPassword = StrCorrectPassword1 _
Or StrUserPassword = StrCorrectPassword2 _
Or IntAttempts = 3
StrUserPassword = InputBox("Invalid Password" _
& "try again.", ApplicationTitle2)
IntAttempts = IntAttempts + 1
Loop
If StrUserPassword = StrCorrectPassword1 Then
MsgBox "Password Accepted", vbInformation _
, ApplicationTitle2
BinNormalExit = True
Else
If StrUserPassword = StrCorrectPassword2 Then
MsgBox "Password Accepted", vbInformation _
, ApplicationTitle2
BinNormalExit = True
Else
x = MsgBox("Invaled Password.Application will be termenated" _
, vbQuestion Or vbYesNo, ApplicationTitle2)
If x = vbNo Then
BinNormalExit = False
ActiveWorkbook.Save
Workbooks.Close
Else
BinNormalExit = False
ActiveWorkbook.Save
Workbooks.Close
End If
End If
End If
End Sub