我对VBA还是很陌生,并且继承了VBA代码,编写此代码的人使用下面的子功能来保护工作表。
有人可以解码以下内容吗?似乎他正在使用特殊字符,但是对于我目前的理解而言,此代码太高级了。
任何指导或反馈将不胜感激。
Public Sub makeSafe(ws As Worksheet, safe As Boolean)
If safe Then
If Not ws.Name = "COMPLETED" Then
ws.Columns("A:B").Locked = False
ws.Columns("D").Locked = False
End If
ws.Protect XOREnc("½ ·Î½ ·", "nope")
Else
ws.Unprotect XOREnc("½ ·Î½ ·", "nope")
End If
End Sub
Function XOREnc(theInput As String, theKey As String) As String
Dim val1, val2 As Integer, out As String, temp As Integer
For i = 1 To Len(theInput)
val1 = Asc(Mid(theInput, i, 1))
val2 = Asc(Mid(theKey, i Mod Len(theKey) + 1, 1))
If val1 Xor val2 < 32 Then
temp = 255 - (val1 Xor val2)
Else
temp = val1 Xor val2
End If
out = out & Chr(temp)
Next i
XOREnc = out
End Function