【问题标题】:VBA Access: How to zip and encrypt a directory from VBA Access?VBA Access:如何从 VBA Access 压缩和加密目录?
【发布时间】:2014-07-29 07:31:13
【问题描述】:

如何使用 Windows 标准 zip 功能使用 VBA Access 压缩目录并加密 zip 文件?

到目前为止,我已经设法找到创建 Zip 文件并将文件从目录移动到 zip 文件的代码。但是 Zip 文件未加密。请参阅下面的代码:

Public Function AddFilesToZip()

Dim objFSO As Object, objZip As Object, objShell As Object
Dim objFolder As Object, objFile As Object
Dim sngStart As Single
Dim strPath As String, strZip As String
Dim inputfile As DAO.Recordset
Set inputfile = CurrentDb.OpenRecordset("SELECT InputFilepath, Format(End_of_Month, 'yyyymmdd')  FROM CONFIG WHERE Active = True;")
strPath = inputfile(0)  'Path to read files from


strZip = strPath & "Test Import Files " & inputfile(1) & ".zip"  'Output zip file

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objZip = objFSO.CreateTextFile(strZip)
objZip.WriteLine Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)
objZip.Close

Set objShell = CreateObject("Shell.Application")
Set objFolder = objFSO.GetFolder(strPath)

    'loop through files - adding them to the zip
For Each objFile In objFolder.Files
    If objFile <> strZip Then
    'objShell.NameSpace("" & strZip).CopyHere objFile.Path
    objShell.NameSpace("" & strZip).MoveHere objFile.Path
    sngStart = Timer
    Do While Timer < sngStart + 2
        DoEvents
    Loop
    End If
Next



End Function

【问题讨论】:

    标签: ms-access encryption vba


    【解决方案1】:

    可能不是您所希望的,但不幸的是,用于压缩(或压缩文件夹)的 Windows shell 功能不进行加密。这是一种非常简单的方法,可以将文件以压缩形式组合在一起,仅此而已。

    创建 zip 文件后,您需要使用第三方工具或库通过 VBA Shell 函数或类似机制调用它来加密您的 zip 文件。当然,缺点是任何此类工具都需要先安装在计算机上才能使用。

    从好的方面来说,你不需要那些笨拙的代码来完成任务的外壳压缩部分,因为这些工具可以同时压缩和加密;只要确保您阅读了需要传递的命令行选项即可。

    【讨论】:

    • 我将如何使用库加密文件?
    • 有 DotNetZip 库,例如,根据其网站,它可以在 VBA 等脚本环境中使用。我没有亲自尝试过,所以我不能肯定地告诉你,尽管第三方工具选项应该可以正常工作,因为它就像在命令行中执行它们一样。
    • 谢谢,我去看看
    猜你喜欢
    • 1970-01-01
    • 2019-04-17
    • 2010-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-03
    • 2015-11-22
    • 1970-01-01
    相关资源
    最近更新 更多