I am trying to handle multiple message objects.
Ultimately, I want to send a message to a list of recipients in a spreadsheet file.
Dim w As Outlook.Application
Dim wInbox As Outlook.MAPIFolder
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim count, x, msgnum As Integer
' Handle Microsoft outlook
Set w = GetObject(, "Outlook.Application")
If Err = ERR_APP_NOTRUNNING Then ' Open new instance if none is running
Set w = New Outlook.Application
wInbox = w.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
End If
'Count number of emails required
count = Cells(1, 2).End(xlDown).Row
msgnum = wInbox.Items.count
For x = 1 To count
Set objOutlookMsg = w.CreateItem(olMailItem)
msgnum = wInbox.Items.count
Next x
——-Edit———
What if I handle the code like this?
Dim w As Outlook.Application
Dim wInbox As Outlook.MAPIFolder
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim count, x, msgnum As Integer
' Handle Microsoft outlook
Set w = GetObject(, "Outlook.Application")
If Err = ERR_APP_NOTRUNNING Then ' Open new instance if none is running
Set w = New Outlook.Application
End If
wInbox = w.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
'Count number of emails required
count = Cells(1, 2).End(xlDown).Row
msgnum = wInbox.Items.count
For x = 1 To count
Set objOutlookMsg = w.CreateItem(olMailItem)
msgnum = wInbox.Items.count
Next x
```
This worked for me…