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
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
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
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