Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encrypting Zip Files with separate Passwords using VBA 1

Status
Not open for further replies.

Shanl14

Technical User
May 26, 2016
2
0
0
US
Hello

I have used the code at this link by PSUIVERSON posted below:

Code:
Dim source As String
Dim target As String
Dim password As String
    
source = Chr$(34) & "C:\DEPTS\050\" & Chr$(34)
target = Chr$(34) & "C:\DEPTS\050\050" & Chr$(34)

password = Chr$(34) & "JORDAN" & Chr$(34)
Shell ("C:\Program Files\WinZip\WINZIP32.EXE -min -a -sPASSWORD " & target & " " & source)

End Function

I was able to password protect the files within the zip, but when trying to unlock those files in the zip, I found that it has applied password instead of JORDAN as the password to lock down the files.

In my project, this piece of script was added to the VBA to encrypt different zip files each with its own password, but even if I change JORDAN to a different variable String (input password from a column in a worksheet) like scripted below, the code does not take the password I provide instead the default word password.

Code:
Dim source As String
Dim target As String
Dim password As String
Dim pwd As String

'within loop x is the row number
pwd = Trim(Records.Cells(x, 6).Text)
source = Chr$(34) & "C:\DEPTS\050\" & Chr$(34)
target = Chr$(34) & "C:\DEPTS\050\050" & Chr$(34)

password = Chr$(34) & pwd & Chr$(34)
Shell ("C:\Program Files\WinZip\WINZIP32.EXE -min -a -spassword " & target & " " & source)

Am I missing something? Anyone please help. Thanks.
 
I would try something like:
[tt]
Shell ("C:\Program Files\WinZip\WINZIP32.EXE -min -a -s[blue] & password & " " [/blue]& target & " " & source)
[/tt]

Just a guess...

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Changed

Code:
Shell ("C:\Program Files\WinZip\WINZIP32.EXE -min -a -spassword " & target & " " & source)

to

Code:
Shell ("C:\Program Files\WinZip\WINZIP32.EXE -min -a -s" & password & " " & target & " " & source)

Posting in case someone else needs this, since I had been hunting for such a code for a long time and was finally able to put it together for my VBA project.

Code:
Dim source As String
Dim target As String
Dim password As String
Dim pwd As String

'within loop x is the row number
pwd = Trim(Records.Cells(x, 6).Text)
source = Chr$(34) & "C:\DEPTS\050\" & Chr$(34)
target = Chr$(34) & "C:\DEPTS\050\050" & Chr$(34)

password = Chr$(34) & pwd & Chr$(34)
Shell ("C:\Program Files\WinZip\WINZIP32.EXE -min -a -s" & password & " " & target & " " & source)

That worked!! THANK YOU Andrzejek!
 
You are welcome! [wiggle]
WOW, a stab in the dark and BINGO!
I should do the same in Powerball...

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top