以下是引用qqqqqqwwwwww在2006-12-20 21:21:00的发言:
可以试一试下面这一段,进行加密,但不能生成.exe文件。如不行请回复!
Sub SetProtect()
Dim FileName As String
FileName = Application.GetOpenFilename("Excel文件(*.xls & *.xla),*.xls;*.xla", , "VBA")
If FileName = CStr(False) Then
Exit Sub
Else
VBAPassword FileName, True
End If
End Sub
Private 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 Protect = False Then
Dim St As String * 2
Dim s20 As String * 1
Get #1, CMGs - 2, St
Get #1, DPBo + 16, s20
For i = CMGs To DPBo Step 2
Put #1, i, St
Next
Dim MMs As String * 5
MMs = "DPB="""
Put #1, CMGs, MMs
MsgBox "加密成功......", 32, "系统提示"
End If
Close #1
End Function
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) | Powered by Discuz! X3.3 |