-1

The below code extracts the rar file but as i am not sure of the location of WinRar, i would need it to check two locations. The below code comes up with a type mismatch error on the 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

I am hoping that it would check either location then run.

Robert Hall
  • 191
  • 3
  • 11
  • You cant put an or into a string like that. You would need to either make two separate strings or create a string array. – Warcupine Jul 02 '19 at 13:21

1 Answers1

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
Robert Hall
  • 191
  • 3
  • 11