View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Password Change with Macro - based on date

One suggestion:


Const BaseDate As Date = #8/20/2007#
Const BasePword As Long = 1234

Sub test()
Dim pword As Long

pword = Date - BaseDate + BasePword
MsgBox pword

End Sub


The date literal is mm/dd/yyyy (U.S. short date format).


"Danny" wrote:

Hi,

I came up with this macro (from this NG) in my workbook.
How can I change the password based on a date?
Example:

8/20/07 = 1234
8/21/07 = 1235
8/22/07 = 1236
Etc.

Thank you.


Private Sub Workbook_BeforePrint(CANCEL As Boolean)

If Date = Now() Then
CANCEL = True

Exit Sub
End If
PassWord = InputBox("Enter Password")
If PassWord = "" Then
CANCEL = True
Exit Sub
End If
If PassWord = "1234" Then

CANCEL = False

'CountPrinting 'Limit printing even with correct date & PW, still on the works
Range("$A1").Select

Else
MsgBox " Try again ?", vb, "Wrong password !"
CANCEL = True
Exit Sub
End If
End Sub