How add password to ZIP folder?

L

LeeL

Hi, i have been using code below to zip files. Can someone help add a line
to add a password to the zip folder? I am zipping text files, so i cannot
password the files . . .
Thanks in advance!

Sub Zip_File()
Dim strDate As String, DefPath As String
Dim oApp As Object
Dim FName, FileNameZip

'********************************************************************
'These values are user inputs which can be loaded in a number of ways
DefPath = "H:\"
FName = "H:\Temp\PSR31M.TXT"
strDate = Format(Now, " dd-mmm-yy h-mm-ss")
FileNameZip = DefPath & "MyFilesZip " & strDate & ".zip"


If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If

'Create empty Zip File
NewZip (FileNameZip)

Set oApp = CreateObject("Shell.Application")

oApp.Namespace(FileNameZip).CopyHere FName

MsgBox "You find the zipfile here: " & FileNameZip
Set oApp = Nothing
End Sub
Sub NewZip(sPath)
'Create empty Zip File
Dim oFSO, arrHex, sBin, i, Zip
Set oFSO = CreateObject("Scripting.FileSystemObject")
arrHex = Array(80, 75, 5, 6, 0, 0, 0, _
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
For i = 0 To UBound(arrHex)
sBin = sBin & Chr(arrHex(i))
Next
With oFSO.CreateTextFile(sPath, True)
.Write sBin
.Close
End With
End Sub

Sub newone()
Dim strDate As String, DefPath As String
Dim oApp As Object
Dim FName, FileNameZip

'********************************************************************
'These values are user inputs which can be loaded in a number of ways
DefPath = "H:\"
FName = "H:\Temp\PSR31M.TXT"
strDate = Format(Now, " dd-mmm-yy h-mm-ss")
FileNameZip = DefPath & "MyFilesZip " & strDate & ".zip"


If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If

'Create empty Zip File
NewZip (FileNameZip)

Set oApp = CreateObject("Shell.Application")

oApp.Namespace(FileNameZip).CopyHere FName

MsgBox "You find the zipfile here: " & FileNameZip
Set oApp = Nothing
End Sub
 
L

LeeL

Thanks, I familiar with the manual way to add, can anyone help with how to
get it done inside VBA code?
 
L

LeeL

Thanks, that one gets close, but it is calling a winzip application from c
drive. I am trying to run on my company network and cannot call wizip...,
below code in my first post does work, it seems like there should be a way
add a line for pasword ... ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top