Results 1 to 10 of 10

Thread: Setting a pwd in code to winzip file

  1. #1

    Thread Starter
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721

    Setting a pwd in code to winzip file

    Hi

    Does anyone using the code below know how to set a pwd on the file
    b4 I winzip it or pwd protect the zipped file?

    Thanks

    Code:
    Sub Zip_Files_in_Folder(filename)
        Dim FileNameZip, FolderName
        Dim strDate As String, DefPath As String
        Dim oApp As Object
    
        'DefPath = Application.DefaultFilePath
        If Right(DefPath, 1) <> "\" Then
            DefPath = DefPath & "\"
        End If
    
        FolderName = "N:\DailyFiles\QuoteAndBuy\ZippedFiles\"    '<< Change
        
        strDate = Format(Now, " dd-mmm-yy")
        FileNameZip = FolderName & "MyFilesZip" & strDate & ".zip"
    
        'Create empty Zip File
        NewZip (FileNameZip)
    
        Set oApp = CreateObject("Shell.Application")
        'Copy the files to the compressed folder
        oApp.NameSpace(FileNameZip).CopyHere filename
    
        'Keep script waiting until Compressing is done
        On Error Resume Next
        Do Until oApp.NameSpace(filename).Items.Count = _
           oApp.NameSpace(filename).Items.Count
            'Application.Wait (Now + TimeValue("0:00:01"))
        Loop
        On Error GoTo 0
    
        msgbox "You find the zipfile here: " & filename
    End Sub
    ** HOLLY **

  2. #2

  3. #3

    Thread Starter
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721

    Re: Setting a pwd in code to winzip file

    if not here were should it be posted???
    ** HOLLY **

  4. #4

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Setting a pwd in code to winzip file

    Thread moved to 'VB6 and Earlier' forum

    Note that the Database Development forum is only for questions related to databases (such as designing them, using them from your VB programs, etc).

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Setting a pwd in code to winzip file

    Do Until oApp.NameSpace(filename).Items.Count = _
    oApp.NameSpace(filename).Items.Count
    surely that must never loop
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721

    Re: Setting a pwd in code to winzip file

    Does anyone have any ideas?
    ** HOLLY **

  8. #8

  9. #9

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Setting a pwd in code to winzip file

    i found a method at http://www.mvps.org/emorcillo/en/code/vb6/index.shtml
    that i was able to modify to make into a function to add password

    requires to download and register oletlib.tlb and oletlib.odl from that site, (first item), instructions on the page

    add timer and module to project

    code for form
    vb Code:
    1. Private Sub Command1_Click()
    2.    fn = "C:\test\ziptest\test.zip"
    3.  
    4. ShowAddPassword (fn)
    5. End Sub
    6.  
    7.  
    8. Private Sub Timer1_Timer()
    9. SendKeys "password"
    10. SendKeys "{TAB}"
    11. SendKeys "password"
    12. SendKeys "~"
    13. Timer1.Enabled = False
    14. End Sub
    add password box flashes briefly, if you prefer you can just fill in the password in the box instead of using timer
    if you use a different form or timer name, change in the module

    anyone wants to convert the sendkeys to sendmessage feel free
    Attached Files Attached Files
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width