HELP - Unzip with Winzip64.exe and Overwrite any existing files

JosephMcCain

New Member
Joined
Jan 30, 2015
Messages
8
Can someone please let me know what is wrong with the code below?
I am trying to unzip a file using winzip64 and I also want to overwrite any existing files that are extracted.

Currently the code runs without errors but it also doesn't extract the file to the location.

Code:
Sub Unzip_With_Overwrite()
    Application.DisplayAlerts = False
    Dim Cur_Date As Date
    Dim fs As Object
    Dim Fname As Variant
    Dim availableWinzipProgram  As String
    Dim DefPath As String
    Dim Filename As String
	Dim latestFile As Variant
	
    Windows("Workbook.xlsm").Activate
    Application.Calculate
    Cur_Date = Workbooks("Workbook.xlsm").Worksheets("Sheet1").Range("A1").Value
    DefPath = "C:\Users\User\Desktop\New Folder\"
    Filename = Dir(DefPath & "*" & Format(Cur_Date, "MMM") & "*.zip", vbNormal)
	
    Do While Filename <> ""
        If FileDateTime(DefPath & Filename) > dtLast Then
            dtLast = FileDateTime(DefPath & Filename)
            latestFile = DefPath & Filename
        End If
        Filename = Dir
    Loop
    Filename = Dir$(latestFile)
    Fname = DefPath & Filename
	
    Set fs = CreateObject("Scripting.FileSystemObject")
    availableWinzipProgram = "C:\Program Files\WinZip\WINZIP64.EXE"
	shellString = availableWinzipProgram & " -e -o " & Fname & " " & DefPath
	
    Application.DisplayAlerts = True
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
when you step through with F8 what is contained in fName I guess I would have chosen it as a string (though I could be wrong)
 
Upvote 0
do you have a user called user, does the target path exist
 
Upvote 0
yes, i just changed that for the forum as to not show private information

this is the code i am currently using but it keeps "crashing" if the file exists

Code:
Sub Unzip_Code()
    Application.DisplayAlerts = False
    Dim Cur_Date As Date
    Dim FSO As Object
    Dim oApp As Object
    Dim Fname As Variant
    Dim FileNameFolder  As Variant
    Dim DefPath As String
    Dim Filename As String
	
    Windows("Workbook.xlsm").Activate
    Application.Calculate
    Cur_Date = Workbooks("Workbook.xlsm").Worksheets("Sheet1").Range("A1").Value
        
    Do While Filename <> ""
        If FileDateTime(DefPath & Filename) > dtLast Then
            dtLast = FileDateTime(DefPath & Filename)
            latestFile = DefPath & Filename
        End If
        Filename = Dir
    Loop
    Filename = Dir$(latestFile)
    Fname = DefPath & Filename

    
    Set oApp = CreateObject("Shell.Application")
    oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(Fname).items
	
    On Error Resume Next
    Set FSO = CreateObject("scripting.filesystemobject")
    FSO.deletefolder Environ("Temp") & "\Temporary Directory*", True
    Application.DisplayAlerts = True
End Sub
 
Upvote 0
This issue has been resolved.

Apparently just adding the ", 16" a "oApp.Namespace(DefPath).CopyHere oApp.Namespace(Fname).items" will overwrite the file.

Code:
Sub Unzip_Code()
    Application.DisplayAlerts = False
    Dim Cur_Date As Date
    Dim FSO As Object
    Dim oApp As Object
    Dim Fname As Variant
    Dim DefPath As Variant
    Dim Filename As String
    Dim Unzip As String
    
    Windows("Workbook.xlsm").Activate
    Application.Calculate
    Cur_Date = Workbooks("Workbook.xlsm").Worksheets("Sheet1").Range("A1").Value
    DefPath = "C:\Users\User\Desktop\snapshot\"
    Filename = Dir(DefPath & "*" & Format(Cur_Date, "MMM") & "*.zip", vbNormal)
    
    Do While Filename <> ""
        If FileDateTime(DefPath & Filename) > dtLast Then
            dtLast = FileDateTime(DefPath & Filename)
            latestFile = DefPath & Filename
        End If
        Filename = Dir
    Loop
    Filename = Dir$(latestFile)
    Fname = DefPath & Filename
    
    Set oApp = CreateObject("Shell.Application")
    oApp.Namespace(DefPath).CopyHere oApp.Namespace(Fname).items, 16
    
    On Error Resume Next
    Set FSO = CreateObject("scripting.filesystemobject")
    FSO.deletefolder Environ("Temp") & "\Temporary Directory*", True
    Application.DisplayAlerts = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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