使用WinZip在子文件夹中压缩文件

时间:2017-08-06 21:24:23

标签: vba winzip

当我使用shell命令行来使用winzip时,在vba中使用命令行时,返回路径和文件名的变量r和q不会识别为字符串。我还需要删除目录中已有的任何zip文件的代码。

Option Explicit
Public Function ZipAll()
Dim objFSO As New Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim colFiles As Scripting.File
Dim objFile As Object
Dim objStartFolder As String
Dim Subfolder As Scripting.Folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "S:\UPSData\EOMOnHand\Abbott\"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
ShowSubFolders objFSO.GetFolder(objStartFolder)
End Function

Public Function ShowSubFolders(Folder)
Dim objFSO As New Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim colFiles As Scripting.File
Dim objFile As Object
Dim objStartFolder As String
Dim Subfolder As Scripting.Folder
Dim r As String
Dim q As String
Dim NextRow As Long
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    NextRow = 1

    For Each Subfolder In Folder.Subfolders
    'MsgBox SubFolder.Path
    Set objFolder = objFSO.GetFolder(Subfolder.Path)
    Set colFiles = objFolder.Files
    For Each objFile In colFiles
    r = Subfolder.Path & "\" & objFile.Name & ".zip"
    q = Subfolder.Path & "\" & objFile.Name
    MsgBox r
    MsgBox q
    Shell "C:\Program Files\WinZip\WinZip64.exe -min -a " & r & " " & q
    NextRow = NextRow + 1
    Next
Next
End Function

当我msgbox时,我返回s:\ upsdata \ eomonhands \ abbott \ abbott.xlsx。我使用thata作为调用winzip的命令行中的文件名,但它不会将其视为字符串。如何将q作为字符串返回。还有什么代码可以过滤掉该文件夹中已经是zip文件的任何其他文件。我不想拉那些。

1 个答案:

答案 0 :(得分:0)

要压缩xlsx子文件夹中的所有文件,您可以执行以下操作:

global

基本上,如果您将过滤器放在文件名上,它将跳转到拉链文件的行并拉开该文件,而不是跳过列出的其他文件。如果在winzp命令行中使用chr(34),则允许它在调用时成为字符串。