Live-Forum - Die aktuellen Beiträge
Datum
Titel
24.04.2024 19:29:30
24.04.2024 18:49:56
Anzeige
Archiv - Navigation
1172to1176
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Datei packen mit Zip.dll ?

Datei packen mit Zip.dll ?
Jörg
Hallo Forum,
ich versuche eine Exceldatei per VBA zu zippen.
Alle Lösungsvorschläge, die ich bislang im Forum gefunden habe verwenden dazu die winzip32.exe-Datei.
Diese ist auf meinem Rechner leider nicht vorhanden, trotzem kann ich aber zippen.
Auf Nachfrage bei unserem IT-Spezialisten wurde mir folgendes mitgeteilt:
„Es gibt kein Winzip auf den Firmenrechnern. Wozu auch. Die Zip.dlls gibt es doch mit Windows.
Am besten diese Dlls via VBA ansprechen.“
Zip.dll's habe ich mehrere auf dem Rechner in unterschiedlichen Verzeichnissen. Kann man per VBA eine Zip.dll auf dem Rechner suchen lassen und anschließend diese Datei zum packen verwenden?
Kann jemand helfen? Besten Dank im voraus,
ciao Jörg

7
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: Datei packen mit Zip.dll ?
19.08.2010 10:46:17
JogyB
Hallo Jörg,
wenn das so einfach ist, dann soll er Dir doch sagen, wie man die anspricht. Ich habe ein wenig rumgegogelt und keinen gefunden, der das hinbekommen hätte.
Aber schau Dir das mal an, das benutzt eine freie DLL für die Komprimierung. Ist zwar für VB, aber solche Geschichten laufen durchaus auch unter VBA, evtl. sind kleine Anpassungen notwendig.
http://www.vbaccelerator.com/home/VB/Code/Libraries/Compression/Zipping_Files/article.asp
Gruß, Jogy
AW: Datei packen mit Zip.dll ?
19.08.2010 15:06:37
Jörg
Hallo Jogy,
danke für den Tip, aber damit bin ich mit meinen bescheidenen VBA Kenntnissen nicht weitergekommen.
Ciao Jörg
Anzeige
ZIP-Funktionalität unter Windows nutzen...
19.08.2010 11:14:21
NoNet
Hallo Jörg,
euer IT-Spezialist hat grundsätzlich recht : In Windows gibt es eine integrierte ZIP-Funktionalität !
Unter Windows XP existiert dazu die Datei "C:\Windows\System32\zipfldr.dll", die evtl. zuerst mit Administrator-Rechten registriert werden muss (in der Eingabeaufforderung - "DOS-Box"):
regsvr32 "C:\Windows\System32\zipfldr.dll"
Nach dem PC-Start existiert dann im Kontextmenü jeder Datei im "Senden an..." Menü der Eintrag "Compressed (Zip) Folder" (habe leider gerade kein deutsches Windows XP vor mir, daher keine Ahnung wie das exakt auf deutsch heißt !). Mit diesem Menü-Eintrag kannst Du beliebige Dateien zippen und per Drag & Drop weitere Dateien auf das ZIP-Archiv ziehen.
Ob das auch unter Windows Vista/Windows 7 funktioniert kann ich momentan auch nicht prüfen...
Komfortabler geht es natürlich wirklich per ZIP-Programm - ich persönlich verwende das kostenlose Tool 7-Zip !
Gruß, NoNet
PS: Ist ja keine EXCEL-relevante Frage, daher gehört diese Frage eigentlich nicht hier in dieses Forum sondern in ein Windows-Forum !!
Anzeige
AW: ZIP-Funktionalität unter Windows nutzen...
19.08.2010 11:52:13
JogyB
Hallo NoNet,
lies doch mal den ersten Satz nach der Anrede nochmal ;)
Gruß, Jogy
AW: ZIP-Funktionalität unter Windows nutzen...
19.08.2010 15:10:20
Jörg
Hallo NoNet,
leider kan ich 7-Zip nicht einsetzten und muß mit dem Microsoft Standard auskommen.
Die von Dir angesprochene Funktionalität im Kontextmenü würde ich gerne nutzen, aber da macht die VBA Aufzeichnung nicht mit. Hast Du einen Tip, wie man diese anspricht oder in welchem Windows-Forum man diese Frage am besten plazieren kann?
Ciao Jörg
Datei packen mit Windows zip Programm
19.08.2010 15:39:29
Anton
Hallo Jörg,
guck dir das hier mal an.
mfg Anton
AW: Datei packen mit Windows zip Programm
20.08.2010 07:53:18
Jörg
Hallo Anton,
hab's heute früh gleich ausprobiert - genau das, was ich brauche!
Besten Dank dafür!
Ciao Jörg
P.S.: Für Dokuzwecke noch der Inhalt von Antons Link
Zip file or files with the default Windows zip program (VBA)
Ron de Bruin (last update 27-Dec-2009)
Go back to the Excel tips page
Information
Warning: The code below is not supported by Microsoft
It is not possible to hide the copy dialog when you copy to a zip folder (only working with normal folders).
Also there is no possibility to avoid that someone can cancel the CopyHere operation or that your VBA
code will be notified that the operation has been cancelled.
Note: Do not Dim for example FileNameZip as String in the code examples.
This must be a Variant, if you change this the code will not work.
If you want to Unzip files see this page on my site.
http://www.rondebruin.nl/windowsxpunzip.htm
See also the the Zip (compress) section on my site for examples for 7-zip and WinZip.
Important
Before we can try one of the macro examples we must copy the following code in a normal module
of your workbook. Every macro use the

Sub NewZip and the first example also use both functions.
See this page how : http://www.rondebruin.nl/code. _
htm

Sub NewZip(sPath)
'Create empty Zip File
'Changed by keepITcool Dec-12-2005
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
' Rob Bovey
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function
Function Split97(sStr As Variant, sdelim As String) As Variant
'Tom Ogilvy
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function
Examples
There are five examples on this page that you can copy in a normal module of your workbook.
Please read the information good above before you start testing the code below.
Browse to the folder you want and select the file or files
Sub Zip_File_Or_Files()
Dim strDate As String, DefPath As String, sFName As String
Dim oApp As Object, iCtr As Long, I As Integer
Dim FName, vArr, FileNameZip
DefPath = Application.DefaultFilePath
If Right(DefPath, 1)  "\" Then
DefPath = DefPath & "\"
End If
strDate = Format(Now, " dd-mmm-yy h-mm-ss")
FileNameZip = DefPath & "MyFilesZip " & strDate & ".zip"
'Browse to the file(s), use the Ctrl key to select more files
FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xl*), *.xl*", _
MultiSelect:=True, Title:="Select the files you want to zip")
If IsArray(FName) = False Then
'do nothing
Else
'Create empty Zip File
NewZip (FileNameZip)
Set oApp = CreateObject("Shell.Application")
I = 0
For iCtr = LBound(FName) To UBound(FName)
vArr = Split97(FName(iCtr), "\")
sFName = vArr(UBound(vArr))
If bIsBookOpen(sFName) Then
MsgBox "You can't zip a file that is open!" & vbLf & _
"Please close it and try again: " & FName(iCtr)
Else
'Copy the file to the compressed folder
I = I + 1
oApp.Namespace(FileNameZip).CopyHere FName(iCtr)
'Keep script waiting until Compressing is done
On Error Resume Next
Do Until oApp.Namespace(FileNameZip).items.Count = I
Application.Wait (Now + TimeValue("0:00:01"))
Loop
On Error GoTo 0
End If
Next iCtr
MsgBox "You find the zipfile here: " & FileNameZip
End If
End Sub

Browse to a folder and zip all files in it
Sub Zip_All_Files_in_Folder_Browse()
Dim FileNameZip, FolderName, oFolder
Dim strDate As String, DefPath As String
Dim oApp As Object
DefPath = Application.DefaultFilePath
If Right(DefPath, 1)  "\" Then
DefPath = DefPath & "\"
End If
strDate = Format(Now, " dd-mmm-yy h-mm-ss")
FileNameZip = DefPath & "MyFilesZip " & strDate & ".zip"
Set oApp = CreateObject("Shell.Application")
'Browse to the folder
Set oFolder = oApp.BrowseForFolder(0, "Select folder to Zip", 512)
If Not oFolder Is Nothing Then
'Create empty Zip File
NewZip (FileNameZip)
FolderName = oFolder.Self.Path
If Right(FolderName, 1)  "\" Then
FolderName = FolderName & "\"
End If
'Copy the files to the compressed folder
oApp.Namespace(FileNameZip).CopyHere oApp.Namespace(FolderName).items
'Keep script waiting until Compressing is done
On Error Resume Next
Do Until oApp.Namespace(FileNameZip).items.Count = _
oApp.Namespace(FolderName).items.Count
Application.Wait (Now + TimeValue("0:00:01"))
Loop
On Error GoTo 0
MsgBox "You find the zipfile here: " & FileNameZip
End If
End Sub

Zip all files in the folder that you enter in the code
Note: Before you run the macro below change the folder in this macro line
FolderName = "C:\Users\Ron\test\"
Sub Zip_All_Files_in_Folder()
Dim FileNameZip, FolderName
Dim strDate As String, DefPath As String
Dim oApp As Object
DefPath = Application.DefaultFilePath
If Right(DefPath, 1)  "\" Then
DefPath = DefPath & "\"
End If
FolderName = "C:\Users\Ron\test\"    '

Zip the ActiveWorkbook
This

Sub will make a copy of the Activeworkbook and zip it in "C:\Users\Ron\test\" with a date-time  _
stamp.
Change this folder or use your default path    Application.DefaultFilePath

Sub Zip_ActiveWorkbook()
Dim strDate As String, DefPath As String
Dim FileNameZip, FileNameXls
Dim oApp As Object
Dim FileExtStr As String
DefPath = "C:\Users\Ron\test\"    ' "\" Then
DefPath = DefPath & "\"
End If
'Create date/time string and the temporary xl* and Zip file name
If Val(Application.Version) 

Zip and mail the ActiveWorkbook
This will only work if you use Outlook as your mail program
This

Sub will send a newly created workbook (copy of the Activeworkbook).
It save and zip the workbook before mailing it with a date/time stamp.
After the zip file is sent the zip file and the workbook will be deleted from your hard disk.

Sub Zip_Mail_ActiveWorkbook()
Dim strDate As String, DefPath As String, strbody As String
Dim oApp As Object, OutApp As Object, OutMail As Object
Dim FileNameZip, FileNameXls
Dim FileExtStr As String
DefPath = Application.DefaultFilePath
If Right(DefPath, 1)  "\" Then
DefPath = DefPath & "\"
End If
'Create date/time string and the temporary xl* and zip file name
If Val(Application.Version) 

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige