VBA to unzip files and overwrite existing files

oseitutuSamuel

Board Regular
Joined
Jul 31, 2015
Messages
82
Hello Guys,

I have a VBA code that unzips the files in a folder. I wish to modify the code so that existing files will automatically be overwritten (without the prompt to confirm).
Any help will be greatly appreciated. Below is the existing code:

Sub UnzipFiles
Dim ShellApp As Object
Dim TargetFile
Dim ZipFolder
TargetFile = "C:\FolderContainingFiles"
ZipFolder = "C:\FolderToReceiveFiles"

MkDir ZipFolder
On Error GoTo ErrorOccurred
' copy the zipped files to the newly created folder
Set ShellApp = CreateObject("Shell.Application")
ShellApp.Namespace(ZipFolder).copyhere _
ShellApp.Namespace(TargetFile).items
MsgBox "The file was unzipped to:" & _
vbNewLine & ZipFolder & vbNewLine & vbNewLine, vbInformation, Installation
intNumOfLicenses = intNumOfLicenses - 1
Sheet1.Cells(1, 1).Value = intNumOfLicenses

End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Some confusing variable names there, but try including this:
Code:
    Dim i As Variant, fileName As String
    With ShellApp
        For i = 0 To .Namespace(TargetFile).Items.Count - 1
            fileName = Mid(.Namespace(TargetFile).Items.Item(i).Path, InStrRev(.Namespace(TargetFile).Items.Item(i).Path, "\") + 1)
            If Dir(ZipFolder & "\" & fileName) <> vbNullString Then Kill ZipFolder & "\" & fileName
        Next
    End With
 
Upvote 0

Forum statistics

Threads
1,215,543
Messages
6,125,423
Members
449,223
Latest member
Narrian

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
Back
Top