ich hatte mir mit Hilfe der Recherche folgendes Makro gebastelt:
Sub verpacken()
Dim sxlpath As String, szippath As String
Dim swinzippath As String
ActiveWorkbook.Save
'Pfadname ExcelDatei
sxlpath = Chr(34) & ActiveWorkbook.FullName & Chr(34)
'Pfadname ZipDatei
szippath = Left(sxlpath, Len(sxlpath) - 4) & "zip" & Chr(34)
'Datei unter neuem Namen speichern
ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "/x" & ActiveWorkbook.Name
'Winzip aufrufen
swinzippath = "C:\programme\winzip\winzip32.exe -a "
Shell swinzippath & szippath & " " & sxlpath
'Ursprungsdatei löschen
Kill Mid(sxlpath, 2, Len(sxlpath) - 2)
'Datei unter altem Namem neu abspeichern
ThisWorkbook.SaveAs Filename:=Mid(sxlpath, 2, Len(sxlpath) - 2)
'Datei mit neuem namen wieder löschen
Kill ActiveWorkbook.Path & "/x" & ActiveWorkbook.Name
'Anwendung schließen
Application.Quit
End Sub
Immer wenn ich in Einzelschritten testete lief es wunderbar, aber sobald der Programmdurchlauf in einem Rutsch erfolgte blieb es stehen.
Ich hab dann nach dem Shell-Befehl für Winzip eine Pause von 2 Sek eingebaut.Das sieht so aus.:
Sub verpacken()
Dim sxlpath As String, szippath As String
Dim swinzippath As String
ActiveWorkbook.Save
'Pfadname ExcelDatei
sxlpath = Chr(34) & ActiveWorkbook.FullName & Chr(34)
'Pfadname ZipDatei
szippath = Left(sxlpath, Len(sxlpath) - 4) & "zip" & Chr(34)
'Datei unter neuem Namen speichern
ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "/x" & ActiveWorkbook.Name
'Winzip aufrufen
swinzippath = "C:\programme\winzip\winzip32.exe -a "
Shell swinzippath & szippath & " " & sxlpath
'Zeitverzögerung
Application.Wait (Now + TimeValue("0:00:02"))
'Ursprungsdatei löschen
Kill Mid(sxlpath, 2, Len(sxlpath) - 2)
'Datei unter altem Namem neu abspeichern
ThisWorkbook.SaveAs Filename:=Mid(sxlpath, 2, Len(sxlpath) - 2)
'Datei mit neuem namen wieder löschen
Kill ActiveWorkbook.Path & "/x" & ActiveWorkbook.Name
'Anwendung schließen
Application.Quit
End
Sub
Seitdem läuft es prima; kann mir das einer erklären?
mfG
Ingo Christiansen