Office中国论坛/Access中国论坛

标题: [求助]VBA有没有真正将代码隐藏起来的方法,就好象VB生成EXE一样 [打印本页]

作者: 求成    时间: 2006-10-18 14:47
标题: [求助]VBA有没有真正将代码隐藏起来的方法,就好象VB生成EXE一样
VBA有没有真正将代码隐藏起来的方法,就好象VB生成EXE一样,不显示代码运行.
显示代码,应该说任何加密都是无效的,真得没有真正好的方法吗?
作者: stanleypan    时间: 2006-10-19 03:39
VBA代码不可能象VB一样真正编绎.
作者: qqqqqqwwwwww    时间: 2006-12-21 05:21
可以试一试下面这一段,进行加密,但不能生成.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

作者: qqqqqqwwwwww    时间: 2006-12-21 05:25
或者可以把代码复制到vb中,然后再编译成exe文件,vb和vba的代码大部分是相同的,试试看行不行?


作者: xmxiaohe    时间: 2006-12-27 02:39
学习下
作者: redlotus    时间: 2007-2-1 07:06
以下是引用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