0
当我使用shell命令行使用winzip时,在vba中使用命令行时,返回路径和文件名的变量r和q不会识别为字符串。还有什么代码,我需要跳过任何已经在目录中的zip文件。使用WinZip在子文件夹中的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.xlsx。我使用thata作为调用winzip的命令行中的文件名,但它不会将其视为字符串。如何将q作为字符串返回。还有什么代码可以过滤掉该文件夹中已经有zip文件的其他文件。我不想压缩这些。
您肯定会在该命令中出现语法错误 - 'C:\ Program Files \ WinZip \ WinZip64.exe -min -as:\ UPSData \ EOMOnHand \ Abbott \ xyz \ abc.xlsxs:\ UPSData \ EOMOnHand \ Abbott \ xyz \ *。xlsx'不会有效,因为'-as:\ UPSData \ EOMOnHand \ Abbott \ xyz \ abc.xlsxs:\ UPSData \ EOMOnHand \ Abbott \ xyz \ *。xlsx'不是一个合理的参数但我没有安装WinZip来检查正确的语法) – YowE3K
@ YowE3K好吧忘了winzip部分。当我到达objfile.Name它说对象需要。我重新编写了代码以包含子文件夹路径。它不会显示名称。 – Atlas80808
“它说对象需要当它击中行ojbFile.Name”,真的吗? '对于每个在colFiles objFile'应该保证它被填充! –