PDA

View Full Version : [SOLVED] Application.EnableCancelKey not working



Allkman
10-28-2016, 04:05 AM
Hello,

I have created "welcome" sheet in excel where i introduce my program and i also want to set TRIAL period for limited time of use.
I Placed code in ThisWorkbook.
Code wont run if i place it in "Welcome" sheet.
User can simply press "X" on MsgBOX or press "ESCAPE" and use program like nothing happened...
Weird thing is that it will start counting negative days like ( You have -1; -2; -3; ect.. Days left)

Option Explicit



Sub Workbook_Open()


Dim Edate As Date

Edate = Format("27/10/2016", "DD/MM/YYYY") 'replaced yesterdays date
If Date > Edate Then
MsgBox ("This worksheet was valid upto " & Format(Edate, "dd-mmm-yyyy") & " and will be closed")
ActiveWorkbook.Close
End If
If Edate - Date < 3 Then
MsgBox ("This worksheet expires on " & Format(Edate, "dd-mmm-yyyy") & " You have " & Edate - Date & " Days left ")
End If
End Sub


I tried: Application.EnableCancelKey nothing changes with this function..

Any suggestions?
Even if i manage to disable escape, user still has option to press "X" on MsgBOX.

For advanced users: Timebombing fails to save log file in C:\.... (in windows 10, but it saves log file in other partition disk`s like D:\ E:\ ect...) dont know about Win7....

Thank you in advance! :)

GTO
10-28-2016, 05:08 AM
I am not following some of your comments, as regardless of how the message box is dismissed, the remaining statements should execute. For starters, rather than having EDate coerce a string into a date, maybe DateSerial.

Not Tested...


Sub Workbook_Open()

Dim Edate As Date

Edate = DateSerial(2016, 10, 27) 'replaced yesterdays date
If Date > Edate Then
MsgBox "This worksheet was valid upto " & Format(Edate, "dd-mmm-yyyy") & " and will be closed"
ThisWorkbook.Saved = True
ThisWorkbook.Close False
Exit Sub
End If
If Edate - Date < 3 Then
MsgBox ("This worksheet expires on " & Format(Edate, "dd-mmm-yyyy") & " You have " & Edate - Date & " Days left ")
End If
End Sub

Allkman
10-28-2016, 06:26 AM
Your solution worked! Thank You GTO! thousands good karma points to you my man! :)
Have a nice weekend! :)

GTO
10-28-2016, 08:27 AM
Thank you for the feedback and a good weekend to you as well :-)

Mark