Help needed for zip files macro

avidlearner

New Member
Joined
Apr 12, 2009
Messages
5
Hi all,

I'm new to this forum and need help with a zip file macro. Basically I need the macro to zip up a number of files separately. I have something like this:

Sub Zipfile1()
Dim source As String
Dim target As String

source = "F:\Macro test\LNSPY.xls"
target = "F:\Macro test\LNSPY.zip"

Shell "C:\Program Files\WinZip\WINZIP32.EXE -a -r " & target & " " & source
End Sub

However, when i run the macro, there's a error saying "No files were found for this operation - nothing to do. (F:\Macro.zip).

Can someone help by telling me what is missing in my macro? Also, can you show me how to create a loop so that after zipping file1 = LNSPY.xls, I can zip up 3 more other files with a different name.

Thanks in advance.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
try like this
Code:
ZipPath = "c:\programme\winzip\winzip32.exe"
  Shell ZipPath & " -a " & target & source & ".zip " & _
    target & source & ".xls"
  Application.Wait Now + TimeSerial(0, 0, 2)
 
Upvote 0
Hi all,

I'm new to this forum and need help with a zip file macro. Basically I need the macro to zip up a number of files separately. I have something like this:

Sub Zipfile1()
Dim source As String
Dim target As String

source = "F:\Macro test\LNSPY.xls"
target = "F:\Macro test\LNSPY.zip"

Shell "C:\Program Files\WinZip\WINZIP32.EXE -a -r " & target & " " & source
End Sub

However, when i run the macro, there's a error saying "No files were found for this operation - nothing to do. (F:\Macro.zip).

Can someone help by telling me what is missing in my macro? Also, can you show me how to create a loop so that after zipping file1 = LNSPY.xls, I can zip up 3 more other files with a different name.

Thanks in advance.

Shell interprets spaces as command sepeartors, you need to enclose them in "

one rougth way

Code:
    If InStr(1, source, " ", vbTextCompare) <> 0 Then
        source = Chr$(34) & source & Chr$(34)
    End If

    If InStr(1, target, " ", vbTextCompare) <> 0 Then
        target = Chr$(34) & target & Chr$(34)
    End If

As far as your 2nd Q.
Build up an Array and loop through this replacing your source and target strings with the new strings.
 
Upvote 0
Hi all,

Thanks for your reply!

Ivan,

I did this and it works! :)

Sub Zipfile1()
Dim source As String
Dim target As String
source = "F:\Macro test\LNSPY.xls"
target = "F:\Macro test\LNSPY.zip"
If InStr(1, source, " ", vbTextCompare) <> 0 Then
source = Chr$(34) & source & Chr$(34)
End If
If InStr(1, target, " ", vbTextCompare) <> 0 Then
target = Chr$(34) & target & Chr$(34)
End If
Shell "C:\Program Files\WinZip\WINZIP32.EXE -a -r " & target & " " & source
End Sub

But I don't really understand or know how to write a loop command. Can you show me how to create a loop so that i can zip for e.g first file - "F:\Macro test\LNSPY.xls" then "F:\Macro test\clean\split.xls"? The loop will zip up all the files i define.

Once again, thanks in advance ;)
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,467
Members
448,965
Latest member
grijken

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top