VBA Outlook Message Attachment - Array Index Out of Bounds

Status
Not open for further replies.

owensnw

New Member
Outlook version
Outlook 2019 64-bit
Email Account
Office 365 Exchange
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----------------------
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
C Outlook 2016 - converting Word VBA to default Outlook message Outlook VBA and Custom Forms 0
R Outlook 2013 VBA I want to put the entire message to clipboard Using Outlook 5
J Outlook 2007 Rules & VBA: How to run a script on a report message (ReportItem) Using Outlook 14
M Outlook VBA Form not finding FOR LOOP -- Error message Outlook VBA and Custom Forms 2
Geldner Problem submitting SPAM using Outlook VBA Form Outlook VBA and Custom Forms 2
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
M Outlook 2016 outlook vba to look into shared mailbox Outlook VBA and Custom Forms 0
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 3
L Fetch, edit and forward an email with VBA outlook Outlook VBA and Custom Forms 2
BartH VBA no longer working in Outlook Outlook VBA and Custom Forms 1
W Can vba(for outlook) do these 2 things or not? Outlook VBA and Custom Forms 2
richardwing Outlook 365 VBA to access "Other Actions" menu for incoming emails in outlook Outlook VBA and Custom Forms 0
J Outlook Rules VBA Run a Script - Multiple Rules Outlook VBA and Custom Forms 0
C Outlook (desktop app for Microsoft365) restarts every time I save my VBA? Using Outlook 1
E Outlook 365 Outlook/VBA Outlook VBA and Custom Forms 11
J VBA for outlook to compare and sync between calendar Outlook VBA and Custom Forms 1
E Outlook VBA change GetDefaultFolder dynamically Outlook VBA and Custom Forms 6
S vba outlook search string with special characters Outlook VBA and Custom Forms 1
U Outlook 2019 VBA run-time error 424 Outlook VBA and Custom Forms 2
G VBA to save selected Outlook msg with new name in selected network Windows folder Outlook VBA and Custom Forms 1
F Excel VBA to move mails for outlook 365 on secondary mail account Outlook VBA and Custom Forms 1
K Outlook Office 365 VBA download attachment Outlook VBA and Custom Forms 2
V vBA for searching a cell's contents in Outlook and retrieving the subject line Outlook VBA and Custom Forms 1
B vBA for exporting excel file from outlook 2016 Outlook VBA and Custom Forms 3
S Excel vba code to manage outlook web app Using Outlook 10
H Custom Outlook Contact Form VBA Outlook VBA and Custom Forms 1
S Problem Checking the available stores in my Inbox (Outlook VBA) Outlook VBA and Custom Forms 0
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
J Want to learn VBA Macros for Outlook. What book can you recommend? Outlook VBA and Custom Forms 2
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
N Outlook Email Rule execution through shortcut keys (VBA codes) Using Outlook 1
A VBA Code in Outlook disappears after first use Outlook VBA and Custom Forms 1
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
G Outlook VBA and Google Calendar ("Events") Outlook VBA and Custom Forms 1
J VBA Outlook : Subject line : Cut and Paste name to heading , number to very end of the body of Email Outlook VBA and Custom Forms 1
B Advanced Search in MS Outlook by VBA and SQL Outlook VBA and Custom Forms 2
K Outlook Archive to PST Files by Date Range VBA Script? Outlook VBA and Custom Forms 1
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
S Find a cell value in excel using outlook vba Using Outlook 1
J Execute Add-In Button from VBA Outlook 2016 Outlook VBA and Custom Forms 1
J Open an outlook email by Subject on MS Access linked table with VBA Outlook VBA and Custom Forms 10
D create an html table in outlook custom form 2010 using vba in MsAccess Outlook VBA and Custom Forms 7
M Slow VBA macro in Outlook Outlook VBA and Custom Forms 5
T Outlook AntiSpam with VBA Outlook VBA and Custom Forms 1

Similar threads

Back
Top