Teste mal diese Version.
17.12.2008 14:29:47
Tino
Hallo,
versuche es mal mit diesem Code.
Gestartet wird über Sub StartZip()
Die Datei wird zuerst gespeichert, danach wird eine Kopie im Temp- Ordner gespeichert.
Aus dieser Kopie wird die Zip- Datei erstellt und die Kopie am Ende wieder gelöscht.
Option Explicit
Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, _
lpExitCode As Long) As Long
Public Const PROCESS_QUERY_INFORMATION = &H400
Public Const STILL_ACTIVE = &H103
Public Sub ShellAndWait(ByVal PathName As String, Optional WindowState)
Dim hProg As Long
Dim hProcess As Long, ExitCode As Long
If IsMissing(WindowState) Then WindowState = 1
hProg = Shell(PathName, WindowState)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, hProg)
Do
GetExitCodeProcess hProcess, ExitCode
DoEvents
Loop While ExitCode = STILL_ACTIVE
End Sub
Sub UnZip_ZipFile_1(FileNameZip As String, FolderName As String, Optional zipOp As String)
Dim PathWinZip As String
Dim ShellStr As String
PathWinZip = "C:\program files\winzip\"
If Dir(PathWinZip & "winzip32.exe") = "" Then
MsgBox "Please find your copy of winzip32.exe and try again"
Exit Sub
End If
ShellStr = PathWinZip & "Winzip32 -min " & zipOp _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " " & Chr(34) & FolderName & Chr(34)
ShellAndWait ShellStr, vbHide
End Sub
Sub StartZip()
Dim strPfad As String, tempPfad As String
' erst mal speichern
ThisWorkbook.Save
'speicherpfad ermitteln
strPfad = IIf(Right$(ThisWorkbook.Path, 1) = "\", ThisWorkbook.Path, ThisWorkbook.Path & "\")
'Temp Ordner ermitteln + Dateiname
tempPfad = IIf(Right$(Environ$("TEMP"), 1) = "\", Environ$("TEMP"), Environ$("TEMP") & "\") & ThisWorkbook.Name
'tempDatei erstellen
ThisWorkbook.SaveCopyAs tempPfad
'Zip- File erstellen
UnZip_ZipFile_1 strPfad & "NeuerDatei.zip", tempPfad, "-a"
Kill tempPfad 'tempadatei löschen
End Sub
Gruß Tino
www.VBA-Excel.de