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