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'應該保證它被填充! –