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