Runtime error 76: Path not found....Zip files in folder...

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi, I'm getting this error message from the following code from this link.
Can someone please help.

Thanks in advance.
PS: If possible i want the files in all the subfolders of this path be zipped together.
The path i have right now is correct but still says not found....


Code:
[/FONT]
[FONT=Courier New]Sub NewZip(sPath)
'Create empty Zip File
'Changed by keepITcool Dec-12-2005
    If Len(Dir(sPath)) > 0 Then Kill sPath
    Open sPath For Output As #1
    Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
    Close #1
End Sub[/FONT]

[FONT=Courier New]Function bIsBookOpen(ByRef szBookName As String) As Boolean
' Rob Bovey
    On Error Resume Next
    bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function[/FONT]

[FONT=Courier New]Function Split97(sStr As Variant, sdelim As String) As Variant
'Tom Ogilvy
    Split97 = Evaluate("{""" & _
                       Application.Substitute(sStr, sdelim, """,""") & """}")
End Function
Sub Zip_All_Files_in_Folder()
    Dim FileNameZip, FolderName
    Dim strDate As String, DefPath As String
    Dim oApp As Object[/FONT]
[FONT=Courier New]    DefPath = Application.DefaultFilePath
    If Right(DefPath, 1) <> "\" Then
        DefPath = DefPath & "\"
    End If[/FONT]
[FONT=Courier New]    FolderName = "C:\Users\Pedie\Desktop\VBA inputbox\"    '<< Change[/FONT]
[FONT=Courier New]    strDate = Format(Now, " dd-mmm-yy h-mm-ss")
    FileNameZip = DefPath & "MyFilesZip " & strDate & ".zip"[/FONT]
[FONT=Courier New]    'Create empty Zip File
    NewZip (FileNameZip)[/FONT]
[FONT=Courier New]    Set oApp = CreateObject("Shell.Application")
    'Copy the files to the compressed folder
    oApp.Namespace(FileNameZip).CopyHere oApp.Namespace(FolderName).items[/FONT]
[FONT=Courier New]    'Keep script waiting until Compressing is done
    On Error Resume Next
    Do Until oApp.Namespace(FileNameZip).items.Count = _
       oApp.Namespace(FolderName).items.Count
        Application.Wait (Now + TimeValue("0:00:01"))
    Loop
    On Error GoTo 0
    MsgBox "You find the zipfile here: " & FileNameZip
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Do you think this is because of my window? I have win_Vista.

Normally/manually there is no way i can zip the file that is why i want vba to do it.


Please recheck for me:)
 
Upvote 0
try to change

DefPath = Application.DefaultFilePath

to

DefPath = "C:\Users\Pedie\Desktop\"

and see if it makes a difference.
 
Upvote 0
Hi Pedie

The code works for me as is, I tested it on my old Vista/ Xl07 setup.
 
Upvote 0
Hi everyone thanks a lot for helping me out.
I think it is my system and not win vista...it does not allow me to manually zip files..

But with the modification done to the code it is working great...!

I event tried posting reply to this thread but error keeps happening may be because of the traffic in this forum :D

Thanks again everyone!
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,413
Members
449,082
Latest member
tish101

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