Hallo alle zsuammen,
ich habe aktuell folgendes Problem: Ich versuche mit der Bibliothek WshShell ein zuvor erstellten Ordner mit PDF-Dateien zu zippen. Der Code sieht folgendermaßen aus:
Private Sub zipFile(strPath As String)
Dim wsh As WshShell
Dim lngErrorCode As Long
Set wsh = New WshShell
Dim strCommand As String
strCommand = Chr(34) & "C:\Program Files\7-Zip\7z.exe" & Chr(34) & _
" a -tzip " & _
Chr(34) & strPath & Chr(34) & _
" " & Chr(34) & strPath & Chr(34)
MsgBox strCommand
lngErrorCode = wsh.Run(strCommand, WindowStyle:=1, WaitOnReturn:=1)
If lngErrorCode <> 0 Then
MsgBox "Oh no! Something went wrong with Wsh!"
Exit Sub
End If
End Sub
Aufruf in der Hauptprozedur:
zipFile ActiveSheet.Parent.Path & "\" & Date
Die Datei hat als Namen das aktuelle Datum, deswegen das Date im Pfad. lngCodeError ist immer 2. Beim Makro, welcher einfach ne zip-Datei auf meinem Desktop zippen soll, funktioniert es und lngCodeError ist 0.
Ich habe das Makro probiert mit einem Makro, welcher auf dem Desktop gespeichert ist. Das funktioniert problemlos:
Sub zipFile()
Dim wsh As WshShell
Dim lngErrorCode As Long
Set wsh = New WshShell
Dim strCommand As String
Dim strPath As String: strPath = "C:\Users\xxx\Desktop\zipfile"
strCommand = Chr(34) & "C:\Program Files\7-Zip\7z.exe" & Chr(34) & _
" a -tzip " & _
Chr(34) & strPath & Chr(34) & _
" " & Chr(34) & strPath & Chr(34)
lngErrorCode = wsh.Run(strCommand, WindowStyle:=0, WaitOnReturn:=1)
If lngErrorCode <> 0 Then
MsgBox "Oh no! Something went wrong with Wsh!"
Exit Sub
End If
End Sub
Ich würde mich sehr über ein hilfreichen Tipp freuen.
MfG,
Eyyub
|