ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Adding the ability to zip files from multiple locations to a vbs script


There may not be a way to do this.  I have seen a few comments about VBS and zip not being compatible. 
The current working VBS script is used to automate adding multiple attachments to an Outlook pre-addressed email and sending it out all at once.  As written, the files can be selected from anywhere on the system by using Ctrl+click to select them and copy/paste or drag-drop to get them to the script which then does the rest.  They all get attached regardless of where they are located once selected. I have never tried to add more than about 10 but I think the only limit is the file-size allowed by Outlook for an attachment.

Most file types can only be attached to an email by first adding them to a zip or other 'protective' shell and adding all the collected files to a single zip when they come from multiple locations is the problem.  There seems to be no way to do this within the bounds of the VBS script and also no way to do it externally and then bring the results back into the script for completion.

If anyone can supply the missing "zip from anywhere" lines to the script it would be appreciated. :)

Somewhere after this line is where I presume it needs to be added.   
..       Set objArgs = WScript.Arguments 'gets paths of selected files   ..
Once the selected paths are set, those files need to be either zipped separately or added to a single larger zip before they are added to the email as attachments so Outlook will process it without choking up.  This works as-is as long as all files are .txt or other allowed file types.

--- Code: Visual Basic ---Option ExplicitDim objArgs, OutApp, oNameSpace, oInbox, oEmailItem, olMailItemDim a, oAttachments, subjectStr, olFormatHTMLolMailItem = 0olFormatHTML = 2Set objArgs = WScript.Arguments 'gets paths of selected filesSet OutApp = CreateObject("Outlook.Application") 'opens OutlookSet oEmailItem = OutApp.CreateItem(olMailItem) 'opens new emailoEmailItem.To = " " = " "For a = 0 to objArgs.Count - 1Set oAttachments = oEmailItem.Attachments.Add(objArgs(a))subjectStr = subjectStr & Right(objArgs(a),Len(objArgs(a))-(InStrRev(objArgs(a),"\"))) & ", " 'recreates the default Subject e.g. Emailing: file1.doc, file2.xlsNextIf subjectStr = "" then subjectStr = "No Subject "oEmailItem.Subject = "" & Left(subjectStr, (Len(subjectStr)-2))oEmailItem.BodyFormat = olFormatHTMLoEmailItem.DisplayoEmailItem.Send
If there is another method of accomplishing the same goals in another language that would be OK as well. :thmbsup:

Note:  Giving credit where credit is due:  This code is originally from the 'Slipstick Outlook Forum' and named 'Joseph's Script Method'
It works extremely well for what it was originally written to do.

You may find this useful:

If you do not need to preserve the directory structure then you could just demp the files in a temp folder. That is if you are sure there will be no name collisions.

Yeah, I think I read everything in StackOverflow and all their sister sites as well.  Plus several including MS Tech Net and all of them are vague to nonexistent about doing what this script does in a way to keep it all on full auto. 

If it requires any interaction then it can't be used as a drag and drop receptacle as I do it now.  Currently, if there is more than one file with same name it follows the normal windows doctrine of using (2) etc for duplicate files but does not stop to ask me anything.  Both copies get attached if they come from different paths.

Generally speaking, there would normally not be duplicates though.
Surprise!  Thanks for a wake up Miles!  I had given up on Stack but this was one I had not read yet and does have some interesting options using Java.

The thing is, if you check the script it does not actually copy or move anything at all.  It attaches the files directly tot he email based on the path to the file to be attached.  There is no point in time that I could perform the compression on all the files without adding a complete section to do that.

I was hoping I could intercept the calls for the files to be attached and run each of them through a compression before the get attached.  I actually would prefer each to be a separate file if possible so a procedure such as this would do that.

As an aside.  While this is more of a 'stunt' than anything else,  I did figure out that I could get by if I simply add the extension of .txt to each file-name.  Then program.exe would become program.exe.txt before being attached and this works perfectly. Outlook sends them with no complaints then.

I found this article how to use 7-zip from vbs:

Another consideration, WinRar is not free but you can seamlessly build in error correction data, say the default 10%, during compression.  And the unRar part is free.  Compression tools like 7-zip can unrar the .rar files.  Zip is quick but it has the inherent problem that if one bit is corrupted the CRC fails.


[0] Message Index

Go to full version