Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UnZip Last saved Zip file and rename File name in Zip

Status
Not open for further replies.

NewUserMo

Technical User
Mar 15, 2015
23
US
Hi All,

I am trying to find VBA code that will unzip the last saved zip file in a folder and rename the csv file in the zipped folder and save it in another folder. Is that possible?
 
Hello, Actually it is - Please see code below


Sub Unzip1()
Dim FSO As Object
Dim oApp As Object
Dim Fname As Variant
Dim FileNameFolder As Variant
Dim DefPath As String
Dim FileName As String

Call DeleteExample1

Fname = Application.GetOpenFilename(filefilter:="Zip Files (*.zip), *.zip", _
MultiSelect:=False)
If Fname = False Then
'Do nothing
Else

DefPath = "I:\temp\"
If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If

FileNameFolder = DefPath & "DTCC Position File " & "\"


Set oApp = CreateObject("Shell.Application")

oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(Fname).items


MyFolder = "I:\temp\My Position File\"

MyFile = Dir(MyFolder & "\*.xls")
MyOldFile = MyFolder & "\" & MyFile
MyNewFile = MyFolder & "\" & "YourFileName_" & Format(Now, "MM.DD.YY") & ".CSV"
Name MyOldFile As MyNewFile

MsgBox "You find the files here: " & FileNameFolder



On Error Resume Next
Set FSO = CreateObject("scripting.filesystemobject")
FSO.deletefolder Environ("Temp") & "\Temporary Directory*", True
End If
End Sub
Sub DeleteExample1()

On Error Resume Next
Kill "I:\temp\DTCC position File\*.*"
On Error GoTo 0
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top