Sub WinRarIt()
' Code by Richard Schollar 01-6-2010
Dim WinRarPath As String 'WinRar.exe location
Dim RarIt As String 'Command line instruction
Dim SourceDir As String 'The source directory
Dim SourceFile As String 'The source file
Dim Source As String 'The combined Rar from path(s)(FROM)
Dim DestDir As String 'The Rarped file directory
Dim DestRarName As String 'The Rarped file
Dim Dest As String 'The combined Rar to path (TO)
'*** Check installation of WinRar ***
WinRarPath = "C:\Program Files\WinRar\"
If Dir(WinRarPath, vbDirectory) = "" Then
MsgBox "WinRar is not installed in the default directory." _
& Chr$(13) & "Archiving of files will not be possible."
Exit Sub
End If
'*** Set the source details ***
SourceDir = "C:Documents and SettingsRichard.DruryDesktop"
SourceFile = "MI File1.xlsx"
Source = SourceDir & "" & SourceFile
'If source name has one or more spaces surround it with ""
If InStr(1, Source, " ", vbTextCompare) <> 0 Then Source = Chr(34) & Source & Chr(34)
'*** Set the destination details
DestDir = "C:Documents and SettingsRichard.DruryDesktop"
'check that it exists
If Dir(DestDir, vbDirectory) = "" Then MkDir DestDir
DestRarName = "Test.Rar"
Dest = DestDir & "" & DestRarName
If InStr(1, Dest, " ", vbTextCompare) <> 0 Then Dest = Chr(34) & Dest & Chr(34)
'*** Do the Rarping ***
RarIt = Shell(WinRarPath & "WinRar.exe a -ep " & Dest & " " & Source, vbNormalFocus)
End Sub