Winzip command line

L

LS

Hi

I am trying to create an automatic weekly back up of a spreadsheet, to
a folder designated by the user. To save space I want to zip the file
using Winzip 9.

I have managed to get the following to work:

Shell (Winzip & " -min" & " -a " & MyZipFileName & " " & ThisWBName)

Where

MyZipFileName = the full path, filename and 'zip' extension to be
created and
ThisWBName = full path and filename of the file to compress.

However, the folder and filename are selected by the user. The above
works fine as long as there are no spaces in the path or file name,
otherwise Winzip generates an error "No files were found for this
action that match your criteria ...". A check of the error log shows
the spaces in the file/folder names were causing the problem. Because
of company policies, I cannot install the Command line add-in, so that
is not an option.

The only solution I can think of so far, is to tell the users not to
allow spaces in the file or folder names, but this is not ideal. Can
anyone suggest how to allow spaces in these names?

TIA

LS
 
J

Jake Marx

Hi LS,

Maybe wrapping the filename and folder name with double-quotes will work?
That works with most DOS commands.

Shell Winzip & " -min" & " -a """ & MyZipFileName & """ """ & ThisWBName &
""""

[assuming Winzip is a variable name]

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
R

Ron de Bruin

Try this testfile LS

It use GetOpenFilename to select a file and zip it.
It will be in the same folder(the zip file)

Sub Zip_Test()
Dim PathWinZip As String, FileNameZip As String, FileNameXls As String
Dim ShellStr As String, strdate As String
Dim Runwzzip As Long
Dim FName As Variant
FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls")
If FName <> False Then

PathWinZip = "C:\program files\winzip\" ' Be sure that this is the path where WinZip is installed.
FileNameZip = Left(FName, Len(FName) - 4) & ".zip "
FileNameXls = Left(FName, Len(FName) - 4) & ".xls"

ShellStr = PathWinZip & "Winzip32 -min -a " _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " " & Chr(34) & FileNameXls & Chr(34)
Runwzzip = Shell(ShellStr, vbHide)
End If
End Sub
 
R

Ron de Bruin

You can change this line

FileNameXls = Left(FName, Len(FName) - 4) & ".xls"

To this if you like

FileNameXls = FName
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top