Sorry if this sounds silly, and I know it's not a lot of code, but I wanted to see if I could create a macro that would, based on a specified date, effectively lock a workbook with a random password. I've pieced together the parts to do it, and it works. What I want to know is, does it look ok/efficient and if not what changes could be made to clean it up. The random password part came from Dave Hawley's reply to someone's post about generating random numbers/strings here on Ozgrid, so I'm pretty sure that code is fine. If I should link to what I found of his, I can certainly add that and I apologize for not doing so already,would just have to find it again. Just curious about how I merged everything.
1) I know that this would never keep someone that knew anything about vba or was persistent enough out of a worksheet...
2) I know the end throws out a msgbox with the password, would obviously take it out if I ever wanted to use it.
3) This was more for me to learn how to 'nest' functions and work to an end than what the result is.
Thanks in advance for any help.
Sub Expired() ' ' If Date < (#9/9/2013#) Then ActiveSheet.Unprotect "" Else: Dim strPassword As String Dim i As Integer For i = 1 To 8 If i Mod 2 = 0 Then strPassword = Chr(Int((90 - 65 + 1) * Rnd + 65)) & strPassword Else strPassword = Int((9 * Rnd) + 1) & strPassword End If Next i MsgBox strPassword ActiveSheet.Protect strPassword End If End Sub