Having a bit of trouble with my code. The code has both a user form with a dropdown list to select the item being attached to the email. When I click the ok button I get "Run-time error '-2147352567 (800200009)': Array index out of bounds." I have tried everything, and can't seem to figure it out.
----------------------UserForm----------------------
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "Muni/Ind Line Card"
.AddItem "Food/Bev Line Card"
.AddItem "OPE W9"
.AddItem "OPE Credit References"
.AddItem "OPE Credit Application"
End With
End Sub
Private Sub CommandButton1_Click()
lstNo = ComboBox1.ListIndex
Unload Me
End Sub
----------------------END UserForm----------------------
----------------------Module----------------------
Public lstNo As Long
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
Set myAttachments = objItem.Attachments
End If
OPEAttachmentMenu.Show
Select Case lstNo1
Case -1
oMail.Subject = objItem.Subject
Case 0
myAttachments.Add "C:\OneDrive - Owens\Line Cards\Owens Pump Line Card.pdf", _
olByValue, 1, "Owens Pump Line Card"
Case 1
myAttachments.Add "C:\OneDrive - Owens\Owens\Line Cards\OwensFoodWine Line Card.pdf", _
olByValue, 1, "Owens Pump Food & Beverage Line Card"
Case 2
myAttachments.Add "C:\OneDrive - Owens\Owens\Financial\W9 2020 NEW.pdf", _
olByValue, 1, "Owens Pump W9"
Case 3
myAttachments.Add "C:\OneDrive - Owens\Owens\Financial\Owens - Credit & Bank References.pdf", _
olByValue, 1, "Owens - Credit & Bank References"
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
----------------------END Module----------------------
----------------------UserForm----------------------
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "Muni/Ind Line Card"
.AddItem "Food/Bev Line Card"
.AddItem "OPE W9"
.AddItem "OPE Credit References"
.AddItem "OPE Credit Application"
End With
End Sub
Private Sub CommandButton1_Click()
lstNo = ComboBox1.ListIndex
Unload Me
End Sub
----------------------END UserForm----------------------
----------------------Module----------------------
Public lstNo As Long
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
Set myAttachments = objItem.Attachments
End If
OPEAttachmentMenu.Show
Select Case lstNo1
Case -1
oMail.Subject = objItem.Subject
Case 0
myAttachments.Add "C:\OneDrive - Owens\Line Cards\Owens Pump Line Card.pdf", _
olByValue, 1, "Owens Pump Line Card"
Case 1
myAttachments.Add "C:\OneDrive - Owens\Owens\Line Cards\OwensFoodWine Line Card.pdf", _
olByValue, 1, "Owens Pump Food & Beverage Line Card"
Case 2
myAttachments.Add "C:\OneDrive - Owens\Owens\Financial\W9 2020 NEW.pdf", _
olByValue, 1, "Owens Pump W9"
Case 3
myAttachments.Add "C:\OneDrive - Owens\Owens\Financial\Owens - Credit & Bank References.pdf", _
olByValue, 1, "Owens - Credit & Bank References"
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
----------------------END Module----------------------