vba Project加密及解密
Function VBAPassword(FileName As String, Optional Protect As Boolean = False)
If Dir(FileName) = "" Then
Exit Function
Else
FileCopy FileName, FileName & ".bak"
End If
Dim GetData As String * 5
Open FileName For Binary As #1
Dim CMGs As Long
Dim DPBo As Long
For I = 1 To LOF(1)
Get #1, I, GetData
If GetData = "CMG=""" Then CMGs = I
If GetData = "[Host" Then DPBo = I - 2: Exit For
Next
If CMGs = 0 Then
MsgBox "請先對VBA編碼設置一個保護密碼...", 32, "提示"
GoTo clo
End If
If Dir(FileName) = "" Then
Exit Function
Else
FileCopy FileName, FileName & ".bak"
End If
Dim GetData As String * 5
Open FileName For Binary As #1
Dim CMGs As Long
Dim DPBo As Long
For I = 1 To LOF(1)
Get #1, I, GetData
If GetData = "CMG=""" Then CMGs = I
If GetData = "[Host" Then DPBo = I - 2: Exit For
Next
If CMGs = 0 Then
MsgBox "請先對VBA編碼設置一個保護密碼...", 32, "提示"
GoTo clo
End If