Have you ever been required to count the number of email attachments in selected emails? It will be tedious if you manually count them. Here we will help you make the counting much easier and quicker with Outlook VBA.
For some reasons, you may need to count the number of attachments in Outlook emails. If you simply want to get the number of attachments in one email, it’ll be considerably easy. But if you desire to count the attachments in several emails, it will be very troublesome to count manually. In general, one of the most common ways is to save all the attachments to a local folder on your computer. Then select them, and the Windows Explorer will tell you the number of the selected items in the status bar.
However, there is no denying that this method is still quite cumbersome. Actually, by means of Outlook VBA, you can quickly get the total number of attachments in the selected Outlook emails. Read on to learn the detailed VBA codes and steps.
Quickly Get the Total Number of Attachments in Selected Emails
- At first, launch Outlook application and go to “Developer” tab.
- Then you can click on “Visual Basic” button. It will bring you to the “Microsoft Visual Basic for Applications” window.
- Next you should open a new module not in use. Select “Insert” > “Module”.
- After that, you have to copy and paste the following VBA codes into it.
Sub CountAttachmentsinSelectedEmails() Dim olSel As Selection Dim oMail As Object Dim AttCount As Long Dim strMsg As String Set olSel = Outlook.Application.ActiveExplorer.Selection For Each oMail In olSel 'To confirm if the selected items are all emails If oMail.Class <> olMail Then strMsg = "Please select mail items only!" nRes = MsgBox(strMsg, vbOKOnly + vbExclamation) Exit Sub End If 'Get the total number of the attachments in selected emails AttCount = oMail.Attachments.Count + AttCount Next strMsg = "There are " & AttCount & " attachments in the " & olSel.Count & " selected emails." nRes = MsgBox(strMsg, vbOKOnly + vbInformation, "Count Attachments") End Sub
- Subsequently, you can exit the “Visual Basic” window and back to Outlook main window. Then you should find and press the down arrow in Quick Access Toolbar and select “More Commands” from the drop down list.
- Later follow the steps shown in the image below.
- Finally you can have a try.
- After selecting several emails, you can hit the new button in Quick Access Toolbar. Subsequently, you will get a message which tells you the number of the attachments in selected emails. It looks like the following image:
- But if you select any items which are meeting requests or responses alike instead of emails, you will get an alert, like the picture below:
React to Occasional Outlook Problems
If you’ve used Outlook for decades, you must have encountered multiple troubles, including Outlook not responding, Outlook freezing, frequent error messages and Outlook PST email corruption and so forth. Have you already mastered any tricks to address them? Generally speaking, you can start Outlook in safe mode, create a new Outlook profile, repair office and disable third party add-ins, etc. In addition, you should also keep a potent repair tool in vicinity, such as DataNumen Outlook Repair. It will come in handy when both backups and the inbox repair tool fails.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including repair corrupt SQL data and outlook repair software products. For more information visit www.datanumen.com