我想使用宏来压缩7z的文件夹,但是当我将参数添加到命令行时,程序会向我显示错误(它是西班牙文,但我认为正确的翻译是“参数不正确”)。
系统错误:Elparámetronoes 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 :(得分:0)
源代码后的命令行中缺少空格:
strCommand = z7Path & " a -tzip " & Chr(34) & ThisWorkbook.Path & "\" & fnDestination & Chr(34) & " " & source & " -m0=lzma2 -mx=9 -aoa"