Consulting

Results 1 to 4 of 4

Thread: Application.EnableCancelKey not working

  1. #1
    VBAX Regular
    Joined
    Sep 2016
    Posts
    14
    Location

    Application.EnableCancelKey not working

    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!
    Last edited by Allkman; 10-28-2016 at 04:18 AM.

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    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

  3. #3
    VBAX Regular
    Joined
    Sep 2016
    Posts
    14
    Location
    Your solution worked! Thank You GTO! thousands good karma points to you my man!
    Have a nice weekend!
    Last edited by Allkman; 10-28-2016 at 06:51 AM.

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Thank you for the feedback and a good weekend to you as well :-)

    Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •