VBA解压文件
使用shell命令
Sub UnRarFile() '
Dim myPath As String
Dim Rarexe As String
'Dim Rarexe As String
Dim myrar As String, target As String
Dim FileString As String
Dim Result As Long
myPath = "F:\Web\"
'rar path
Rarexe = "C:\Program Files\7-Zip\7z.exe"
'the feil need to be decompressed
myrar = myPath & "2020_06_08.zip"
target = myPath & "2020_06_08"
' Debug.Print myrar
'rar程序的X命令,用来解压缩文件的字符串,-o- 跳过已存在的文件,-o+ 直接覆盖己存在文件
FileString = Rarexe & " " & " X " & " " & myrar & " -o" & target
' Debug.Print FileString
Result = Shell(FileString, vbHide)
End Sub
这里使用的解压工具是7-z,如果使用WinRAR可能是命令字符不同
如果需要覆盖原先解压的文件,则将”-o“改成”-aoa -o“