shrydvd
New Member
- Outlook version
- Outlook 2019 64-bit
- Email Account
- IMAP
I am hoping someone can pull me out of this . . . I am trying to identify emails that have attachments then zip those attachments together with a password. I end up with different errors but can't seem to get it. One of the main errors is with PKZip in the command line saying "Nothing to do". I am sure it has something to do with how I am trying to tell it which files to zip.
Anyway, here is what I have. It is a mixed bag of pieces I have gotten elsewhere and trying to put them together.
If I am way off base and need to scrap it & start over, please tell me that as well. Also, there is likely extraneous junk in the code below simply because I keep trying different things.
Thank you for any guidance you can provide.
Anyway, here is what I have. It is a mixed bag of pieces I have gotten elsewhere and trying to put them together.
If I am way off base and need to scrap it & start over, please tell me that as well. Also, there is likely extraneous junk in the code below simply because I keep trying different things.
Thank you for any guidance you can provide.
Code:
Sub ZipdAttach()
Dim objMail As Outlook.MailItem
Dim objAttachments As Outlook.Attachments
Dim objAttachment As Outlook.Attachment
Dim objFileSystem As Object
Dim objShell As Object
Dim varTempFolder As Variant
Dim varZipFile As Variant
Dim myDir As String
Dim dest As Variant
Dim srce As Variant
Dim strCommand As String
Dim val As String
'Save the attachments to Temporary folder
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
varTempFolder = objFileSystem.GetSpecialFolder(2).Path & "\Temp " & Format(Now, "dd-mm-yyyy- hh-mm-ss-")
MkDir (varTempFolder)
varTempFolder = varTempFolder & "\"
Set objMail = Outlook.Application.ActiveInspector.CurrentItem
Set objAttachments = objMail.Attachments
For Each objAttachment In objAttachments
objAttachment.SaveAsFile (varTempFolder & objAttachment.FileName)
Next
'Create a new zip file
varZipFile = InputBox("Specify a name for the new zip file", "Name Zip File", objMail.Subject)
varZipFile = varTempFolder & varZipFile
'Copy all the saved attachments to the new zip file
Set objShell = CreateObject("Shell.Application")
'_______________________________________________
val = InputBox("Give me an 8 character password.")
myDir = "C:\Program Files\PKWARE\PKZIPC"
dest = varZipFile
srce = varTempFolder
strCommand = "pkzipc.exe -add -passphrase=" & val & " " & dest & " " & srce
Call Shell("cmd.exe /k cd /d " & myDir & " & " & strCommand, 1)
End Sub