【发布时间】: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