Hallo an alle!
Ich habe ein Problem mit einem Code, den ich im Netz gefunden habe. Mit nachfolgendem Code werden alle Dateien in einem Verzeichnis als Zip-Datei mit dem Standard-Zippprogramm von WindowsXP verpackt.
Option Explicit
Sub NewZip(sPath)
If Len(Dir(sPath)) > 0 Then Kill sPath
Open sPath For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
End Sub
Function bIsBookOpen(ByRef szBookName As String) As Boolean
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function
Function Split97(sStr As Variant, sdelim As String) As Variant
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function
Sub Export_Zip_Datei_erzeugen()
Dim FileNameZip, ZipPath
Dim strDate As String, savePath As String
Dim oApp As Object
'Pfad, in das die Zipdatei abgelegt werden soll
savePath = "C:\"
'Pfad, der verpackt werden soll
ZipPath = "C:\Export\"
FileNameZip = savePath & "Export.zip"
On Error Resume Next
Kill FileNameZip
'Create empty Zip File
NewZip (FileNameZip)
Set oApp = CreateObject("Shell.Application")
'Copy the files to the compressed folder
oApp.Namespace(FileNameZip).CopyHere oApp.Namespace(ZipPath).items
'Keep script waiting until Compressing is done
On Error Resume Next
Do Until oApp.Namespace(FileNameZip).items.Count = oApp.Namespace(ZipPath).items.Count
Application.Wait (Now + TimeValue("0:00:01"))
Loop
On Error GoTo 0
Set oApp = Nothing
End Sub
Das funktioniert auch soweit. Allerdings gibt es Probleme, wenn z.B. WinZip installiert ist. Dann erhalte ich folgende Fehlermeldung
Ausgabedatei kann nicht erstellt werden.
Woran kann das liegen, bzw. wie kann ich die Daten verpacken egal welches Programm installiert ist?
Danke Euch und Gruß,
Kasimir