


This code snippet will attach all four files to the same email, assuming all the files reside in the C:\Work Files folder:Īttaching the Current Spreadsheet to an Email using VBAĪttaching files by name is very easy, but you have to know the full filepath to be able to do it. Since we have only the filenames (and file extensions) in our list, we will need to concatenate the path of the folder that contains them. We can iterate through the Files to Send column and attach all of them to a single email. List of Files to Send along with the intended recipients Add method for each file that you want to attach.Ī common task might be to attach several files you have in a list on a spreadsheet and send them to someone (or someones). If you want to attach multiple files, it’s as simple as using the. In last week’s post, we attached a single file and went on our way. Using VBA to Attach Multiple Files to One Email The MailItem object is rather extensive, which is why we will leave that for another time. However you open it, a window will appear in the VBE in which you can inspect all the currently instantiated variables. But if you want to play, you can inspect the collection via the Locals window.Īlternatively, if you prefer keyboard shortcuts, Alt+V > S should open the Locals window.

Navigating through the Attachments collection is somewhat complex, so we will leave that for another time. This is a common naming scheme in VBA to differentiate between singular objects and collections of those objects, so if you come across this singular/plural naming scheme in the future, you will already know the difference! Specifically, it holds Attachment objects.Īt first the nomenclature may seem a bit confusing, but you can think of the singular, Attachment, as the actual attachment and the plural, Attachments, as the collection. It’s really a Collection, which means it holds other objects. CreateItem ( olMailItem ) End SubĪs stated above, the Attachments object is not a string. Sub base_for_attachment_email () Dim outlookApp As Outlook. Using early binding so we get Intellisense, our foundation for this tutorial will be this code: This snippet just creates the objects we need to start with before we can make a full block of code. Here I want to reiterate what was shown in the setup of last week’s post. Example for Attaching the Current Workbook.We’ve talked about collections before when describing how to remove duplicates from an array. But the Attachments object is actually a collection, so it’s a little more complicated. You can read from and write to them pretty naturally. Strings are very basic in computer science, and they’re easy to manipulate. If you remember, the properties we modified were all strings. Last week, we introduced how to send emails with Excel VBA and described the methods and properties of an Outlook MailItem object.
