My copy of pkzipc.exe is "C:\program files\pkware\pkzipc\pkzipc.exe
This seemed to work ok for me:
Option Explicit
Sub testme01()
Application.ScreenUpdating = False
Dim myFiles() As String
Dim fCtr As Long
Dim iCtr As Long
Dim myFile As String
Dim myPath As String
Dim CurLocation As String
CurLocation = CurDir
myPath = "c:\my documents\excel\test"
If Right(myPath, 1) <> "\" Then
myPath = myPath & "\"
End If
myFile = Dir(myPath & "*.xls")
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If
'get the list of files
fCtr = 0
Do While myFile <> ""
fCtr = fCtr + 1
ReDim Preserve myFiles(1 To fCtr)
myFiles(fCtr) = myFile
myFile = Dir()
Loop
ChDrive myPath
ChDir myPath
If fCtr > 0 Then
For iCtr = LBound(myFiles) To UBound(myFiles)
Application.StatusBar _
= "Processing: " & myFiles(iCtr) & " at: " & Now
Shell "command.com /c " & Chr(34) _
& "c:\program files\pkware\pkzipc\pkzipc.exe" & Chr(34) _
& " -add " _
& Chr(34) & Left(myFiles(iCtr), Len(myFiles(iCtr)) - 4) & ".zip" _
& Chr(34) & " " _
& Chr(34) & myFiles(iCtr) & Chr(34), vbMaximizedFocus
Next iCtr
End If
ChDrive CurLocation
ChDir CurLocation
With Application
.ScreenUpdating = True
.StatusBar = False
End With
End Sub
I wanted to see if the command actually finished ok:
When I was testing, I used "command.com /k" to see the DOS window. (I think in
winNT, the equivalent is "cmd.exe /c" (or /k). (maybe winXP, too????))
In either case, you can actually just delete the "command /c " from the shell
command when you're sure it works.
And you could use vbMinimizedFocus instead of having the window maximized, too.
See Shell in VBA's help for the options.