Friday, December 18, 2015

Liberating Excel

My Son, as Captain America
At work, we have to do a bi-weekly timesheet and a monthly timesheet.  The administrative types send out bi-weekly timesheets each every two weeks.

They didn't send me one.  That's not a problem, I think.  I can just create a copy, and change the dates.

Nope, they password protected the sheet.  It's nearly the end of the day, before a holiday week, I'm taking vacation the next week, and I have to have my timesheet in just a few minutes,

Thanks to The University of Wisconsin, Green Bay (https://uknowit.uwgb.edu/page.php?id=28850), here is a quick answer.  Simple brute-force the password with Excel's handy VBA editor.

Sub PasswordBreaker() 'Breaks worksheet password protection.
    Dim i As Integer, j As Integer, k As Integer
    Dim l As Integer, m As Integer, n As Integer
    Dim i1 As Integer, i2 As Integer, i3 As Integer
    Dim i4 As Integer, i5 As Integer, i6 As Integer
    On Error Resume Next
    For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
    For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
    For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
    For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
    ActiveSheet.Unprotect Chr(i) & Chr(j) & Chr(k) & _ Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If ActiveSheet.ProtectContents = False Then
MsgBox "One usable password is " & Chr(i) & Chr(j) & _
Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
Exit Sub
End If
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
End Sub
Worked like a charm, and I submitted my timesheet with time to spare!

Friday, December 11, 2015

Not Not Null

The Natural Beauty of West Virginia
So while moving a database from SQL 2000 to SQL 2008 R2, we ran into a problem.  A date/time field defined as "NOT NULL" and had a default value of GETDATE().  The probelem was that the inserts were failing.  I determined that the server was doing the NULL check before applying the default value.

So I attempted to remove the NOT NULL constraint from the designer, but it told me I would have to drop and create the table.

Stackoverflow had the answer. Oryol's solution was to use SQL to alter the table and column together with this command:

alter table TableName alter column ColumnName int null