VBA unzipping a file without confirmation with a Shell script

Tinkerz

Board Regular
Joined
Feb 26, 2007
Messages
179
Hi,

I found this script on the internet and am using it to unzip a file, but I get a confirmation button to press if the file is already there.

I either need to delete the zip file first, if there is one, or dont have the confirmation screen, how do I go about that?

Sub TestRun()

'Change this as per your requirement

Call UnZip("C:\Users\NeilWin7DB\Trading\ExcelFiles\", "C:\Users\NeilWin7DB\Trading\ExcelFiles\Historical_NAV_Outstanding_AUM.zip")

End Sub


Sub UnZip(strTargetPath As String, fname As Variant)

Dim oApp As Object, FSOobj As Object
Dim FileNameFolder As Variant

If Right(strTargetPath, 1) <> Application.PathSeparator Then
strTargetPath = strTargetPath & Application.PathSeparator
End If

FileNameFolder = strTargetPath

'create destination folder if it does not exist
Set FSOobj = CreateObject("Scripting.FilesystemObject")
If FSOobj.FolderExists(FileNameFolder) = False Then
FSOobj.CreateFolder FileNameFolder
End If

Set oApp = CreateObject("Shell.Application")
oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(fname).items

Set oApp = Nothing
Set FSOobj = Nothing
Set FileNameFolder = Nothing

End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Look, I am not nearly as good at this program as many gurus on here, but I may have a solve for you.

At the beginning of both macros, type:

Application.DisplayAlerts = False
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,823
Members
449,470
Latest member
Subhash Chand

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