I currently have a VBA scrip that is running in Outlook where it pops up a listbox. The user selects the attachment, then it is added to the current email and unloads the user form. Now we are wondering if we can do multi-select and choose multiple attachments to go to the email. Here is the listbox:
Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then Cancel = True
End Sub
Private Sub CommandButton2_Click()
End
End Sub
Private Sub CommandButton1_Click()
lstNo = ListBox1.ListIndex
Unload Me
End Sub
Private Sub ListBox1_Change()
End Sub
Private Sub UserForm_Initialize()
With ListBox1
.AddItem "-----------Credit------------"
.AddItem "OPE W9"
.AddItem "OPE Credit References"
.AddItem "OPE Credit Application"
.AddItem "----------Brochures----------"
.AddItem "Vogelsang Municipal Brochure"
.AddItem "Vogelsang Wine Brochure"
.AddItem "Vogelsang XR Buyers Guide"
.AddItem "Barnes Sithe Brochure"
.AddItem "Barnes SH Brochure"
.AddItem "Barnes Razor Brochure"
.AddItem "Barnes Pressure Sewer Brochure"
.AddItem "Barnes Upgrade Core Brochure"
.AddItem "Barnes Blade Brochure"
.AddItem "Barnes FRP Engineered Basins Brochure"
.AddItem "Mencarelli Wine Pump Brochure"
.AddItem "WasteCorp Municipal Brochure"
.AddItem "WasteCorp Industrial Brochure"
.AddItem "WasteCorp Double-Disc Brochure"
.AddItem "WasteCorp Self-Priming Brochure"
.AddItem "WasteCorp Pre-Packaged Lift Station Brochure"
.AddItem "BioGill Tower Plus Datasheet"
.AddItem "BioGill Ultra Datasheet"
.AddItem "BioGill Brewery Overview"
.AddItem "BioGill Food/Bev Overview"
.AddItem "ARO FDA / Food Compliant Pumps"
.AddItem "ARO 1.5 Inch Diaphragm Pump Cart Flyer"
.AddItem "ARO 2.5 Inch Diaphragm Pump Cart Flyer"
.AddItem "ARO Metalic Diaphragm Pump Brochure"
.AddItem "ARO Non-Metalic Diaphragm Pump Brochure"
.AddItem "Cloacina Product Card"
.AddItem "Cloacina Wine Introduction & Advantages"
.AddItem "Cloacina Wine Brochure"
.AddItem "Cloacina Mempac Mini Package"
.AddItem "Cloacina CEMPAC Thickener Brochure"
.AddItem "OpenChannelFlow Parshall Flume Brochure"
.AddItem "OpenChannelFlow Single Piece Shelters Brochure"
.AddItem "OpenChannelFlow Grinder Manhole Brochure"
.AddItem "AK Industries SS 1.25 & 2 Inch Rail Systems"
.AddItem "AK Industries SS 1.25 - 6 Inch Rail Systems"
.AddItem "AK Industries FRP Basins & Accessories"
.AddItem "Prime Solution RFP Family Brochure"
.AddItem "Prime Solution Simple Dewatering Solutions"
.AddItem "Prime Solution RFP Brochure"
.AddItem "Prime Solution RFP2.0 Brochure"
.AddItem "Prime Solution RFSP Brochure"
.AddItem "Prime Solution INT Thickener Brochure"
.AddItem "FOGRod Level Control Brochure"
.AddItem "FOGRod Level Control Presentation"
End With
End Sub
Then here is the code that calls for the object and has all the cases:
Public Sub AddOPEAttachments()
Dim objItem As Object
Dim oMail As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
If TypeName(Application.ActiveInspector.CurrentItem) = "MailItem" Then
Set objItem = Application.ActiveInspector.CurrentItem
End If
Set myAttachments = objItem.Attachments
OPEAttachmentMenu.Show
Select Case lstNo
Case -1
'oMail.Subject = objItem.Subject
Case 0
myAttachments.Add "C:\OneDrive - Pump\Pump\Financial\W9 2020 NEW.pdf", _
olByValue, 1, "NOTHING"
' Pump Information
Case 1
myAttachments.Add "C:\OneDrive - Pump\ Pump\Financial\W9 2020 NEW.pdf", _
olByValue, 1, "Pump W9"
Case 2
myAttachments.Add "C:\OneDrive - Pump\Pump\Financial\Pump - Credit & Bank References.pdf", _
olByValue, 1, " Pump - Credit & Bank References"
Case 3
myAttachments.Add "C:\OneDrive - Pump\Pump\Forms DOC\General Information\Pump Credit Application.pdf", _
olByValue, 1, " Pump - Credit Application"
objItem.HTMLBody = "See the attached credit application and return, or complete it online at the link: " & vbNewLine & vbNewLine & "<a href=""http://credit.pump.com"">Click Here</a>"
Case 4
myAttachments.Add "C:\OneDrive - Pump\Pump\Financial\W9 2020 NEW.pdf", _
olByValue, 1, "NOTHING"
'Vogelsang Information
Case 5
myAttachments.Add "C:\OneDrive - Pump\Venders\Vogelsang\Brochures\Vogelsang Municipal Brochure.pdf", _
olByValue, 1, "Vogelsang Municipal Brochure"
Case 6
myAttachments.Add "C:\OneDrive - Pump\Venders\Vogelsang\Brochures\Vogelsang Wine Brochure-sm.pdf", _
olByValue, 1, "Vogelsang Wine Brochure"
Case 7
myAttachments.Add "C:\OneDrive - Pump\Venders\Vogelsang\Brochures\Vogelsang XRipper Buyers Guide 2019-sm.pdf", _
olByValue, 1, "Vogelsang XRipper Brochure"
'Barnes Information
Case 8
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\Barnes Sithe Brochure.pdf", _
olByValue, 1, "Barnes Sithe Brochure"
Case 9
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\Barnes SH Brochure.pdf", _
olByValue, 1, "Barnes SH Brochure"
Case 10
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\Barnes Razor Brochure.pdf", _
olByValue, 1, "Barnes Razor Brochure"
Case 11
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\2020 Pressure Sewer Market Brochure.pdf", _
olByValue, 1, "Barnes Pressure Sewer Brochure"
Case 12
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\2020 Upgrade Core Brochure.pdf", _
olByValue, 1, "Barnes Upgrade Cores Brochure"
Case 13
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\Barnes Blade Brochure XP sm.pdf", _
olByValue, 1, "Barnes Blade Brochure"
Case 14
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\Barnes Engineered Basins Brochurepdf", _
olByValue, 1, "Barnes FRP Engineered Basins Brochure"
'Mencarelli Information
Case 15
myAttachments.Add "C:\OneDrive - Pump\Venders\Mencarelli Pump & Valve\Brochure\Mencarelli Inox Pump Brochure - Wine OPE.pdf", _
olByValue, 1, "Mencarelli Wine Pump Brochure"
'WasteCorp Information
Case 16
myAttachments.Add "C:\OneDrive - Pump\Venders\WasteCorp Pumps\Brochures\WasteCorp Municipal Pumps Brochure.pdf", _
olByValue, 1, "WasteCorp Municipal Brochure"
Case 17
myAttachments.Add "C:\OneDrive - Pump\Venders\WasteCorp Pumps\Brochures\WasteCorp Industrial Pumps Brochure.pdf", _
olByValue, 1, "WasteCorp Municipal Brochure"
Case 18
myAttachments.Add "C:\OneDrive - Pump\Venders\WasteCorp Pumps\Brochures\WasteCorp Double-Disc Brochure.pdf", _
olByValue, 1, "WasteCorp Double-Disc Brochure"
Case 19
myAttachments.Add "C:\OneDrive - Pump\Venders\WasteCorp Pumps\Brochures\WasteCorp Trash Flow Self Priming Brochure.pdf", _
olByValue, 1, "WasteCorp Self-Priming Brochure"
Case 20
myAttachments.Add "C:\OneDrive - Pump\Venders\WasteCorp Pumps\Brochures\WasteCorp Pre-Packaged Lift Stations Brochure.pdf", _
olByValue, 1, "WasteCorp Pre-Packaged Lift Station Brochure"
'BioGill Information
Case 21
myAttachments.Add "C:\OneDrive - Pump\Venders\BioGill\Brochures\BioGill Tower Plus DataSheet.pdf", _
olByValue, 1, "BioGill Tower Plus Datasheet"
Case 22
myAttachments.Add "C:\OneDrive - Pump\Venders\BioGill\Brochures\BioGill Ultra DataSheet.pdf", _
olByValue, 1, "BioGill Ultra Datasheet"
Case 23
myAttachments.Add "C:\OneDrive - Pump\Venders\BioGill\Brochures\20180510BioGIllBreweryWastewaterTreatmentGuideVersion1.3.pdf", _
olByValue, 1, "BioGill Brewery Treatment Guide"
Case 24
myAttachments.Add "C:\OneDrive - Pump\Venders\BioGill\Brochures\20180606FoodBeverageOverview.pdf", _
olByValue, 1, "BioGill Food & Bev Overview"
'ARO Information
Case 25
myAttachments.Add "C:\OneDrive - Pump\Venders\ARO Pumps\Brochures & Flyers\ARO FDA Compliant AOD Pumps OPE.pdf", _
olByValue, 1, "ARO FDA & Food Diaphragm Pumps Brochure"
Case 26
myAttachments.Add "C:\OneDrive - Pump\Venders\Pumps\Brochures & Datasheets\1.5 TC AOD Wine Cart OP.pdf", _
olByValue, 1, "ARO 1.5 Inch Diaphragm Pump Cart Flyer"
Case 27
myAttachments.Add "C:\OneDrive - Pump\Venders\Pumps\Brochures & Datasheets\2.5 TC AOD Wine Cart OP.pdf", _
olByValue, 1, "ARO 2.5 Inch Diaphragm Pump Cart Flyer"
Case 28
myAttachments.Add "C:\OneDrive - Pump\Venders\ARO Pumps\Brochures & Flyers\EXP Metalic Pumps.pdf", _
End Select
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select
Set objApp = Nothing
End Function
Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then Cancel = True
End Sub
Private Sub CommandButton2_Click()
End
End Sub
Private Sub CommandButton1_Click()
lstNo = ListBox1.ListIndex
Unload Me
End Sub
Private Sub ListBox1_Change()
End Sub
Private Sub UserForm_Initialize()
With ListBox1
.AddItem "-----------Credit------------"
.AddItem "OPE W9"
.AddItem "OPE Credit References"
.AddItem "OPE Credit Application"
.AddItem "----------Brochures----------"
.AddItem "Vogelsang Municipal Brochure"
.AddItem "Vogelsang Wine Brochure"
.AddItem "Vogelsang XR Buyers Guide"
.AddItem "Barnes Sithe Brochure"
.AddItem "Barnes SH Brochure"
.AddItem "Barnes Razor Brochure"
.AddItem "Barnes Pressure Sewer Brochure"
.AddItem "Barnes Upgrade Core Brochure"
.AddItem "Barnes Blade Brochure"
.AddItem "Barnes FRP Engineered Basins Brochure"
.AddItem "Mencarelli Wine Pump Brochure"
.AddItem "WasteCorp Municipal Brochure"
.AddItem "WasteCorp Industrial Brochure"
.AddItem "WasteCorp Double-Disc Brochure"
.AddItem "WasteCorp Self-Priming Brochure"
.AddItem "WasteCorp Pre-Packaged Lift Station Brochure"
.AddItem "BioGill Tower Plus Datasheet"
.AddItem "BioGill Ultra Datasheet"
.AddItem "BioGill Brewery Overview"
.AddItem "BioGill Food/Bev Overview"
.AddItem "ARO FDA / Food Compliant Pumps"
.AddItem "ARO 1.5 Inch Diaphragm Pump Cart Flyer"
.AddItem "ARO 2.5 Inch Diaphragm Pump Cart Flyer"
.AddItem "ARO Metalic Diaphragm Pump Brochure"
.AddItem "ARO Non-Metalic Diaphragm Pump Brochure"
.AddItem "Cloacina Product Card"
.AddItem "Cloacina Wine Introduction & Advantages"
.AddItem "Cloacina Wine Brochure"
.AddItem "Cloacina Mempac Mini Package"
.AddItem "Cloacina CEMPAC Thickener Brochure"
.AddItem "OpenChannelFlow Parshall Flume Brochure"
.AddItem "OpenChannelFlow Single Piece Shelters Brochure"
.AddItem "OpenChannelFlow Grinder Manhole Brochure"
.AddItem "AK Industries SS 1.25 & 2 Inch Rail Systems"
.AddItem "AK Industries SS 1.25 - 6 Inch Rail Systems"
.AddItem "AK Industries FRP Basins & Accessories"
.AddItem "Prime Solution RFP Family Brochure"
.AddItem "Prime Solution Simple Dewatering Solutions"
.AddItem "Prime Solution RFP Brochure"
.AddItem "Prime Solution RFP2.0 Brochure"
.AddItem "Prime Solution RFSP Brochure"
.AddItem "Prime Solution INT Thickener Brochure"
.AddItem "FOGRod Level Control Brochure"
.AddItem "FOGRod Level Control Presentation"
End With
End Sub
Then here is the code that calls for the object and has all the cases:
Public Sub AddOPEAttachments()
Dim objItem As Object
Dim oMail As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
If TypeName(Application.ActiveInspector.CurrentItem) = "MailItem" Then
Set objItem = Application.ActiveInspector.CurrentItem
End If
Set myAttachments = objItem.Attachments
OPEAttachmentMenu.Show
Select Case lstNo
Case -1
'oMail.Subject = objItem.Subject
Case 0
myAttachments.Add "C:\OneDrive - Pump\Pump\Financial\W9 2020 NEW.pdf", _
olByValue, 1, "NOTHING"
' Pump Information
Case 1
myAttachments.Add "C:\OneDrive - Pump\ Pump\Financial\W9 2020 NEW.pdf", _
olByValue, 1, "Pump W9"
Case 2
myAttachments.Add "C:\OneDrive - Pump\Pump\Financial\Pump - Credit & Bank References.pdf", _
olByValue, 1, " Pump - Credit & Bank References"
Case 3
myAttachments.Add "C:\OneDrive - Pump\Pump\Forms DOC\General Information\Pump Credit Application.pdf", _
olByValue, 1, " Pump - Credit Application"
objItem.HTMLBody = "See the attached credit application and return, or complete it online at the link: " & vbNewLine & vbNewLine & "<a href=""http://credit.pump.com"">Click Here</a>"
Case 4
myAttachments.Add "C:\OneDrive - Pump\Pump\Financial\W9 2020 NEW.pdf", _
olByValue, 1, "NOTHING"
'Vogelsang Information
Case 5
myAttachments.Add "C:\OneDrive - Pump\Venders\Vogelsang\Brochures\Vogelsang Municipal Brochure.pdf", _
olByValue, 1, "Vogelsang Municipal Brochure"
Case 6
myAttachments.Add "C:\OneDrive - Pump\Venders\Vogelsang\Brochures\Vogelsang Wine Brochure-sm.pdf", _
olByValue, 1, "Vogelsang Wine Brochure"
Case 7
myAttachments.Add "C:\OneDrive - Pump\Venders\Vogelsang\Brochures\Vogelsang XRipper Buyers Guide 2019-sm.pdf", _
olByValue, 1, "Vogelsang XRipper Brochure"
'Barnes Information
Case 8
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\Barnes Sithe Brochure.pdf", _
olByValue, 1, "Barnes Sithe Brochure"
Case 9
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\Barnes SH Brochure.pdf", _
olByValue, 1, "Barnes SH Brochure"
Case 10
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\Barnes Razor Brochure.pdf", _
olByValue, 1, "Barnes Razor Brochure"
Case 11
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\2020 Pressure Sewer Market Brochure.pdf", _
olByValue, 1, "Barnes Pressure Sewer Brochure"
Case 12
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\2020 Upgrade Core Brochure.pdf", _
olByValue, 1, "Barnes Upgrade Cores Brochure"
Case 13
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\Barnes Blade Brochure XP sm.pdf", _
olByValue, 1, "Barnes Blade Brochure"
Case 14
myAttachments.Add "C:\OneDrive - Pump\Venders\Crane Pump & Systems\Technical\Barnes Pump\Brochures\Barnes Engineered Basins Brochurepdf", _
olByValue, 1, "Barnes FRP Engineered Basins Brochure"
'Mencarelli Information
Case 15
myAttachments.Add "C:\OneDrive - Pump\Venders\Mencarelli Pump & Valve\Brochure\Mencarelli Inox Pump Brochure - Wine OPE.pdf", _
olByValue, 1, "Mencarelli Wine Pump Brochure"
'WasteCorp Information
Case 16
myAttachments.Add "C:\OneDrive - Pump\Venders\WasteCorp Pumps\Brochures\WasteCorp Municipal Pumps Brochure.pdf", _
olByValue, 1, "WasteCorp Municipal Brochure"
Case 17
myAttachments.Add "C:\OneDrive - Pump\Venders\WasteCorp Pumps\Brochures\WasteCorp Industrial Pumps Brochure.pdf", _
olByValue, 1, "WasteCorp Municipal Brochure"
Case 18
myAttachments.Add "C:\OneDrive - Pump\Venders\WasteCorp Pumps\Brochures\WasteCorp Double-Disc Brochure.pdf", _
olByValue, 1, "WasteCorp Double-Disc Brochure"
Case 19
myAttachments.Add "C:\OneDrive - Pump\Venders\WasteCorp Pumps\Brochures\WasteCorp Trash Flow Self Priming Brochure.pdf", _
olByValue, 1, "WasteCorp Self-Priming Brochure"
Case 20
myAttachments.Add "C:\OneDrive - Pump\Venders\WasteCorp Pumps\Brochures\WasteCorp Pre-Packaged Lift Stations Brochure.pdf", _
olByValue, 1, "WasteCorp Pre-Packaged Lift Station Brochure"
'BioGill Information
Case 21
myAttachments.Add "C:\OneDrive - Pump\Venders\BioGill\Brochures\BioGill Tower Plus DataSheet.pdf", _
olByValue, 1, "BioGill Tower Plus Datasheet"
Case 22
myAttachments.Add "C:\OneDrive - Pump\Venders\BioGill\Brochures\BioGill Ultra DataSheet.pdf", _
olByValue, 1, "BioGill Ultra Datasheet"
Case 23
myAttachments.Add "C:\OneDrive - Pump\Venders\BioGill\Brochures\20180510BioGIllBreweryWastewaterTreatmentGuideVersion1.3.pdf", _
olByValue, 1, "BioGill Brewery Treatment Guide"
Case 24
myAttachments.Add "C:\OneDrive - Pump\Venders\BioGill\Brochures\20180606FoodBeverageOverview.pdf", _
olByValue, 1, "BioGill Food & Bev Overview"
'ARO Information
Case 25
myAttachments.Add "C:\OneDrive - Pump\Venders\ARO Pumps\Brochures & Flyers\ARO FDA Compliant AOD Pumps OPE.pdf", _
olByValue, 1, "ARO FDA & Food Diaphragm Pumps Brochure"
Case 26
myAttachments.Add "C:\OneDrive - Pump\Venders\Pumps\Brochures & Datasheets\1.5 TC AOD Wine Cart OP.pdf", _
olByValue, 1, "ARO 1.5 Inch Diaphragm Pump Cart Flyer"
Case 27
myAttachments.Add "C:\OneDrive - Pump\Venders\Pumps\Brochures & Datasheets\2.5 TC AOD Wine Cart OP.pdf", _
olByValue, 1, "ARO 2.5 Inch Diaphragm Pump Cart Flyer"
Case 28
myAttachments.Add "C:\OneDrive - Pump\Venders\ARO Pumps\Brochures & Flyers\EXP Metalic Pumps.pdf", _
End Select
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select
Set objApp = Nothing
End Function