Anführungszeichen in Zip-Passwort
23.04.2020 09:43:39
Micha
ich habe das Problem, dass es vorkommen kann, dass in einem Passwort zur 7Zip-Verschlüsselung ein " (z.B. 123"4568) vorkommen kann. Wenn dies der Fall ist, dann wird nicht verzippt und der Code bricht ab.
Das Passwort wird in die Variable strPasswort aus der Textbox tbpassword welche sich auf der UserForm1 befindet geladen.
Kann mir bitte Jemand helfen ?
Danke.
Sub E_Zip_ActiveWorkbook()
Dim PathZipProgram As String, NameZipFile As String
Dim ShellStr As String, strDate As String, DefPath As String
Dim FileNameXls As String, TempFilePath As String, TempFileName As String
Dim MyWb As Workbook, FileExtStr As String
Dim strPasswort As String
strPasswort = UserForm1.tbpassword
'Path of the Zip program
' PathZipProgram = "C:\Temp\7zip\App\7-Zip\"
PathZipProgram = "C:\program files\7-Zip\"
If Right(PathZipProgram, 1) "\" Then
PathZipProgram = PathZipProgram & "\"
End If
'Check if this is the path where 7z is installed.
If Dir(PathZipProgram & "7z.exe") = "" Then
MsgBox "Please find your copy of 7z.exe and try again"
Exit Sub
End If
'Build the path and name for the new xls? file
Set MyWb = ActiveWorkbook
If ActiveWorkbook.Path = "" Then Exit Sub
TempFilePath = Environ$("temp") & "\"
FileExtStr = "." & LCase(Right(MyWb.Name, _
Len(MyWb.Name) - InStrRev(MyWb.Name, ".", , 1)))
TempFileName = Left(MyWb.Name, Len(MyWb.Name) - Len(FileExtStr))
'Use SaveCopyAs to make a copy of the file
FileNameXls = TempFilePath & TempFileName & FileExtStr
MyWb.SaveCopyAs FileNameXls
DefPath = ActiveWorkbook.Path ' & Format(Date, "DD.MM.YYYY")
If Right(DefPath, 1) "\" Then
DefPath = DefPath & "\"
End If
strDate = Format(Now, "yyyy-mm-dd h-mm-ss")
NameZipFile = DefPath & TempFileName & ".7z"
'Zip FileNameXls (copy of the ActiveWorkbook)
ShellStr = PathZipProgram & "7z.exe a -r -p" & strPasswort & " -mhe" _
& " " & Chr(34) & NameZipFile & Chr(34) _
& " " & Chr(34) & FileNameXls & Chr(34)
'ShellStr = PathZipProgram & "7z.exe a" _
& " " & Chr(34) & NameZipFile & Chr(34) _
& " " & Chr(34) & FileNameXls & Chr(34)
ShellAndWait ShellStr, vbHide
Kill TempFilePath & TempFileName & FileExtStr
End Sub