vba code to select file and unzip files in a different folder with different name

karthikha0706

New Member
Joined
Oct 30, 2013
Messages
44
HI All, Am looking for a vba code to select a file from a folder and unzip the file in a different folder with different file name. Can you please assist me with the code.
Thanks in advance.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

karthikha0706

New Member
Joined
Oct 30, 2013
Messages
44
So each of your real text filename starts with only 3 letters and forever, never be changed ?​
Yes Marc. Your understanding is correct. Also, i would like to overwrite the 3 csv files daily when i unzip the files in a particular folder.
 

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,145
Office Version
  1. 2010
Platform
  1. Windows
So each zip file contains a single text file only which has always the same name as the zip file ?​
 

karthikha0706

New Member
Joined
Oct 30, 2013
Messages
44
So each zip file contains a single text file only which has always the same name as the zip file ?​
Yes Marc. However date is attached to the zip file . For example today i will get the file as ABC070721.zip and tomorrow ABC080721.zip and so on....
 

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,145
Office Version
  1. 2010
Platform
  1. Windows

ADVERTISEMENT

Last option : once a file extracted and renamed should its zip container be deleted from the source folder ?​
 

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,145
Office Version
  1. 2010
Platform
  1. Windows
Last question as there are different ways : is the destination folder C:\XYZ always empty (or without any .csv text file) before the zip extraction ?​
 

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,145
Office Version
  1. 2010
Platform
  1. Windows

ADVERTISEMENT

Forget previous question, just answer to post #15 …​
 

karthikha0706

New Member
Joined
Oct 30, 2013
Messages
44
Last option : once a file extracted and renamed should its zip container be deleted from the source folder ?​
Yes Marc. No issues, we can delete the zip files once the csv files are extracted at the required folder.
 

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,145
Office Version
  1. 2010
Platform
  1. Windows
A VBA demonstration for starters :​
VBA Code:
Sub DemoUnZip1()
      Const D = "C:\XYZ\", S = "C:\Download\", C = ".csv"
        Dim Z$, oSh As Object, F$, N$
    With CreateObject("Scripting.FileSystemObject")
            Z = Dir$(S & "*.zip"):  If Z = "" Or Not .FolderExists(D) Then Beep: Exit Sub
            Set oSh = CreateObject("Shell.Application")
        Do
               F = oSh.NameSpace(S & Z).Items.Item(0).Name
            If F Like "???######" & C Then
                oSh.NameSpace(D).CopyHere oSh.NameSpace(S & Z).ParseName(F), 16
                N = D & Left$(F, 3) & C:  If .FileExists(N) Then .DeleteFile N, True
               .MoveFile D & F, N
               .DeleteFile S & Z, True
            End If
                   Z = Dir$
        Loop Until Z = ""
             Set oSh = Nothing
    End With
End Sub
 

karthikha0706

New Member
Joined
Oct 30, 2013
Messages
44
Last question as there are different ways : is the destination folder C:\XYZ always empty (or without any .csv text file) before the zip extraction ?​
No Marc. The destination folder XYZ contains other csv files.....and previous days extraction of
Forget previous question, just answer to post #15 …​
Last question as there are different ways : is the destination folder C:\XYZ always empty (or without any .csv text file) before the zip extraction ?​
No Marc. The destination folder XYZ contains other csv files.....and previous days extraction of abc.csv, def.csv and ghi.csv
 

Forum statistics

Threads
1,136,765
Messages
5,677,618
Members
419,707
Latest member
Anna vib

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top