以下代码提取了rar文件,但是由于我不确定WinRar的位置,因此我需要使用它检查两个位置。以下代码在WinRarPath上出现类型不匹配错误。
Sub Extract()
Dim RarIt As String
Dim Source As String
Dim Desti As String
Dim WinRarPath As String
WinRarPath = "C:\Program Files\WinRar\" Or "C:\Program Files (x86)\WinRar\"
Source = "C:\VBA\VBA.rar"
Desti = "C:\VBA\"
RarIt = Shell(Chr(34) & WinRarPath & "WinRar.exe" & Chr(34) & " e " & Chr(34) & Source & Chr(34) & " " & Chr(34) & Desti & Chr(34), vbNormalFocus)
Application.Wait (Now + TimeValue("0:00:02"))
Kill Source
End Sub
我希望它可以检查任何一个位置然后运行。
答案 0 :(得分:0)
Sub Extract()
Dim RarIt As String
Dim Source As String
Dim Desti As String
Dim WinRarPath As String
Dim WinRarPathX86 As String
WinRarPath = "C:\Program Files\WinRar\"
WinRarPathX86 = "C:\Program Files (x86)\WinRar\"
Source = "C:\VBA\VBA.rar"
Desti = "C:\VBA\"
If Dir("C:\Program Files\WinRar\", vbDirectory) <> "" Then
RarIt = Shell(Chr(34) & WinRarPath & "WinRar.exe" & Chr(34) & " e " & Chr(34) & Source & Chr(34) & " " & Chr(34) & Desti & Chr(34), vbNormalFocus)
Else
RarIt = Shell(Chr(34) & WinRarPathX86 & "WinRar.exe" & Chr(34) & " e " & Chr(34) & Source & Chr(34) & " " & Chr(34) & Desti & Chr(34), vbNormalFocus)
End If
Application.Wait (Now + TimeValue("0:00:02"))
Kill Source
End Sub