我正在使用这段代码将文件夹中的所有文件压缩到一个新创建的.zip
文件中:
Dim FileNameZip, FolderName
Dim filename As String, DefPath As String
Dim oApp As Object
(defining all paths needed)
'Create empty Zip File
NewZip (FileNameZip)
Set oApp = CreateObject("Shell.Application")
'Copy the files to the compressed folder
oApp.Namespace(FileNameZip).CopyHere oApp.Namespace(FolderName).items
'Keep script waiting until Compressing is done
On Error Resume Next
Do Until oApp.Namespace(FileNameZip).items.Count = oApp.Namespace(FolderName).items.Count
Application.Wait (Now + TimeValue("0:00:01"))
Loop
只要目标文件夹与我的文件所在的文件夹不同,这个方法就可以顺利运行而不出问题。
但是当我试图将一个文件夹中的所有文件压缩成.zip
并生成位于同一文件夹中的归档文件时,我遇到了一个问题——它会创建该归档文件,并尝试将其放入归档文件夹中,这当然会失败。
我正在寻找一种方法,可以压缩除新创建的文件以外的文件夹中的所有文件。
我在这里找到了资料:https://msdn.microsoft.com/en-us/library/office/ff869597.aspx,但这看起来非常适用于Outlook,我没有办法将其应用到Windows文件夹中。