ich habe im Internet einen Code gefunden mit dem ich Zip Dateien über VBA unzipen kann. Jetzt würde ich diese gerne im Anschluss öffnen aber das klapp nicht so ganz. Die zip Datei hat immer den gleichen namen wie die CSV Datei die in der Zip Datei steckt. Leider wird dieser name nicht dem Workbookopen befehl übergeben ka warum.
Oder gibt es eine Möglichkeit das ich die ungezipte datei und deren pfad einer Variablen übergebe und somit weiter verwenden kann?
Sub A_UnZip_Zip_File_Browse()
Dim PathZipProgram As String, NameUnZipFolder As String
Dim FileNameZip As Variant, ShellStr As String
'Path of the Zip program
PathZipProgram = "C:\program files\7-Zip\"
If Right(PathZipProgram, 1) "\" Then
PathZipProgram = PathZipProgram & "\"
End If
'Check if this is the path where 7z is installed.
If Dir(PathZipProgram & "7z.exe") = "" Then
MsgBox "Please find your copy of 7z.exe and try again"
Exit Sub
End If
NameUnZipFolder = "C:\Users\hans\Desktop\Neuer Ordner"
'Select the zip file (.zip or .7z files)
FileNameZip = Application.GetOpenFilename(filefilter:="Zip Files, *.zip, 7z Files, *.7z", _
MultiSelect:=False, Title:="Select the file that _
you want to unzip")
'Unzip the files/folders from the zip file in the NameUnZipFolder folder
If FileNameZip = False Then
'do nothing
Else
ShellStr = PathZipProgram & "7z.exe x -aoa -r" _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " -o" & Chr(34) & NameUnZipFolder & Chr(34) & " " & "*.*"
ShellAndWait ShellStr, vbHide
End If
Workbooks.Open Filename:=FileNameZip
On Error Resume Next
CreateObject("Scripting.FileSystemObject").DeleteFile FileNameZip
End Sub