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
Re: Setting a pwd in code to winzip file
Why is this posted in database forum? :confused:
Re: Setting a pwd in code to winzip file
if not here were should it be posted??? :blush::blush:
Re: Setting a pwd in code to winzip file
Since you're using VB6 I would post it in that forum instead.
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).
Re: Setting a pwd in code to winzip file
Quote:
Do Until oApp.NameSpace(filename).Items.Count = _
oApp.NameSpace(filename).Items.Count
surely that must never loop
Re: Setting a pwd in code to winzip file
Does anyone have any ideas? :blush::blush:
Re: Setting a pwd in code to winzip file
Please don't bump your threads.
Re: Setting a pwd in code to winzip file
Perhaps this article will give you some idea.
1 Attachment(s)
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:
Private Sub Command1_Click()
fn = "C:\test\ziptest\test.zip"
ShowAddPassword (fn)
End Sub
Private Sub Timer1_Timer()
SendKeys "password"
SendKeys "{TAB}"
SendKeys "password"
SendKeys "~"
Timer1.Enabled = False
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