2016-11-30 42 views
0

我想使用宏壓縮與7z文件夾,但是當我將參數添加到命令行程序顯示我與他們的錯誤(這是在西班牙語,但我想,正確的翻譯是「不正確的參數」)。VBA不正確的參數使用7z與命令

System error: El parámetro no es correcto.

有子程序:

Sub ZipDLEFolder() 

Dim strCommand As String 
Dim z7Path As String 
Dim fnDestination As String 
Dim source As String 

z7Path = ThisWorkbook.Sheets("Sheet2").Range("J5") 
fnDestination = ThisWorkbook.Sheets("Sheet2").Range("J6") 
source = Chr(34) & ThisWorkbook.Path & "\" & ThisWorkbook.Sheets("Sheet2").Range("D6") & Chr(34) 
strCommand = z7Path & " a -tzip " & Chr(34) & ThisWorkbook.Path & "\" & fnDestination & Chr(34) & " " & source & "-m0=lzma2 -mx=9 -aoa" 

ThisWorkbook.Sheets("Sheet2").Range("J23") = strCommand 
Shell strCommand, 1 

的參數,使文件的最小版本在一封電子郵件中使用很重要。在以前的版本我用了一個.bat文件,並能正常工作:

@ECHO OFF 
REM Set variable 
set "destiny=%~dp0folder.7z" 
set "source=%~dp0\folder" 

Rem compress the file 
c:\program files\7-zip\7z.exe a -t7z %destiny% %source% -m0=lzma2 -mx=9 -aoa 

exit 

回答

0

的空間被源失蹤後,在命令行中:

strCommand = z7Path & " a -tzip " & Chr(34) & ThisWorkbook.Path & "\" & fnDestination & Chr(34) & " " & source & " -m0=lzma2 -mx=9 -aoa" 
+0

感謝您的信息。但子程序與缺少的空間具有相同的行爲。 – Tilan04

+0

執行該行後strCommand的值是多少? –

+0

這是「c:\ program files \ 7-zip \ 7z.exe」a -tzip「H:\ folder.7z」「H:\ folder」-m0 = lzma2 -mx = 9 -aoa – Tilan04