Private Sub ESTRAI ()
Dim fso As Object
Dim oApp As Object
Dim Fname As Variant
Dim FileNameFolder As Variant
Dim DefPath As String
Dim strDate As String
Dim fileNameInZip As Variant
Dim myPath, MyFileFound
Dim F As Object
Dim Fi As Object
Dim v, num As Long
Dim MyFile
UserForm1.Hide
Rows("2:65000").Select
Selection.Delete Shift:=xlUp
Range("A2").Select
FILETOOPEN = Application.GetOpenFilename("ZIP Files (*.ZIP), *.ZIP", , "Seleziona la cartella", "Apri", "False")
file_selezionato = ActiveWorkbook.Name
If FILETOOPEN = False Then
Application.CutCopyMode = False
End
End If
Application.ScreenUpdating = False
Range("Z1").Value = CurDir
'INSERISCO IL NOME E IL PERCORSO NEL FILE
Application.DisplayAlerts = False
MyFile = ActiveWorkbook.FullName
num = 0
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Application.DisplayAlerts = False
myPath = CurDir
Set F = fso.GetFolder(myPath)
For Each Fi In F.Files
If LCase(fso.GetExtensionName(Fi.Path)) = "zip" Then
Range("a" & num + 2) = Fi
num = num + 1
End If
Next
If Range("A2") = "" Then
Exit Sub
Else
conta = Application.WorksheetFunction.CountA(Range("A2:A65000"))
End If
For i = 2 To conta + 1
Fname = Range("A" & i)
DefPath = Application.DefaultFilePath
If Right(DefPath, 1) <> "" Then
DefPath = DefPath & ""
End If
strDate = Format(Now, " dd-mm-yy h-mm-ss")
FileNameFolder = DefPath & "MyUnzipFolder " & strDate & ""
MkDir FileNameFolder
Set oApp = CreateObject("Shell.Application")
For Each fileNameInZip In oApp.Namespace(Fname).items
If LCase(fileNameInZip) Like LCase("*.txt") Then
oApp.Namespace(FileNameFolder).CopyHere _
oApp.Namespace(Fname).items.Item(CStr(fileNameInZip))
End If
xxx = fileNameInZip
Next
On Error Resume Next
Set fso = CreateObject("scripting.filesystemobject")
fso.DeleteFolder Environ("Temp") & "Temporary Directory*", True
Set f2 = fso.GetFile(DefPath & "MyUnzipFolder " & strDate & "" & xxx)
f2.Move (Range("Z1") & "" & xxx)
fso.DeleteFolder (DefPath & "MyUnzipFolder " & strDate)
Kill Range("A" & i)
Next i
End Sub |