Mình đang tìm hiểu về cách Unzip file bằng VBA.
Tuy nhiên, mỗi lần mình Unzip file xong thì cửa sổ chứa file vừa unzip thì nó tự mở lên.
Dưới đây là đoạn code của nó.
Mong mọi người hướng dẫn cách không cho nó tự mở thư mục đó.
Sub UnZipFile(FileName As String)
Dim CmdLine As String
Dim Ext As Long
Dim FilePath As String
Dim RetVal As Long
Dim Path As Long
Dim ZipName As String
Dim FolderPath As String
Path = InStrRev(FileName, "")
FilePath = "C:\MyDownloads"
FolderPath = "C:\MyDownloads"
If Dir(FilePath & FileName) = "" Then
MsgBox "File Not Found" & vbCrLf & " " & FilePath & FileName
Exit Sub
End If
Ext = InStrRev(FileName, ".")
ZipName = FilePath & IIf(Ext = 0, FileName & ".zip", Left(FileName, Ext) & "zip")
If ZipName <> "" Then
CmdLine = "-min -e " & " " & Chr$(34) & ZipName & Chr$(34) & " " _
& FolderPath
RetVal = ShellExecute(0&, "", "WinZip32.exe", CmdLine, FilePath, 1&)
Msg = "Thanh Cong " & RetVal
MsgBox Msg, vbExclamation + vbOKOnly
End If
End Sub
Tuy nhiên, mỗi lần mình Unzip file xong thì cửa sổ chứa file vừa unzip thì nó tự mở lên.
Dưới đây là đoạn code của nó.
Mong mọi người hướng dẫn cách không cho nó tự mở thư mục đó.
Sub UnZipFile(FileName As String)
Dim CmdLine As String
Dim Ext As Long
Dim FilePath As String
Dim RetVal As Long
Dim Path As Long
Dim ZipName As String
Dim FolderPath As String
Path = InStrRev(FileName, "")
FilePath = "C:\MyDownloads"
FolderPath = "C:\MyDownloads"
If Dir(FilePath & FileName) = "" Then
MsgBox "File Not Found" & vbCrLf & " " & FilePath & FileName
Exit Sub
End If
Ext = InStrRev(FileName, ".")
ZipName = FilePath & IIf(Ext = 0, FileName & ".zip", Left(FileName, Ext) & "zip")
If ZipName <> "" Then
CmdLine = "-min -e " & " " & Chr$(34) & ZipName & Chr$(34) & " " _
& FolderPath
RetVal = ShellExecute(0&, "", "WinZip32.exe", CmdLine, FilePath, 1&)
Msg = "Thanh Cong " & RetVal
MsgBox Msg, vbExclamation + vbOKOnly
End If
End Sub