Visual Basic/Excel | Condition with "Date"

Solved
Hello,

I created a calculation tool for my work.

It's pretty good, and I would like to protect it, but I'm stuck on something really simple.

It all takes place in the VBA project => Microsoft Excel Objects => ThisWorkbook

I'm going through there because when the file opens, I want it to compare the date. If today’s date is greater than 25/03/2010 (for example), then I want it to load a specific UserForm that will require a password to use the Excel file; otherwise, I want to close the Excel file!

Anyway, in ThisWorkbook I put this code:
Private Sub Workbook_Open() Application.WindowState = xlMaximized 'I ask to enlarge the window for aesthetics Sheets("Accueil").Select 'I want the tool to open on my home page If Date > "25/03/2011" Then 'Here I set my condition UserForm10.Show 'I launch a UserForm if the condition is met Else: UserForm1.Show 'Otherwise, I launch this UserForm End If End Sub 

If I set Date > "27/01/2011", I will get the first UserForm, and if I set Date > "28/01/2011", I get the second UserForm (because it is the 28th), so I want to say everything is perfect!

But as soon as I put Date > "25/03/2011" (or even 20/02/2011), well, as soon as I get out of January, I feel like it doesn’t work anymore, and it constantly loads the first UserForm...

It's like it doesn’t recognize today’s date...

How can I modify this piece of code that seems correct to me so that it works regardless of the fixed deadline?

A big thank you in advance, hoping that you can help me :)

Thanks to everyone!

Configuration: Windows XP / Safari 534.10

2 answers

  1. I love you Pikachu, ehhhh pijaku :D

    It works wonderfully!

    Yes, it's a matter of variable type...

    I've seen quite a few tutorials but I must admit I'm still having trouble with all of this.

    In any case, a big thank you to you and have a great weekend!
    0