Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outlook 2013 using VBA to Send Drafts

Tags:

vba

outlook

Good morning,

Using Outlook 2010 I compiled code to send all emails that were saved in a drafts folder of a given account. Now I've upgraded to Office 2013 I am getting an error... It is the .Send bit where it falls over and presents the error message:

"This method can't be used with an inline response mail item."

I am certain that there is a v simple method for sending drafts, but I have scoured the web and can't figure it as yet.

Public Sub SendDrafts()

Dim lDraftItem As Long
Dim myOutlook As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolders As Outlook.Folders
Dim myDraftsFolder As Outlook.MAPIFolder

'Send all items in the "Drafts" folder that have a "To" address filled

'Setup Outlook

Set myOutlook = Outlook.Application
Set myNameSpace = myOutlook.GetNamespace("MAPI")
Set myFolders = myNameSpace.Folders

'Set Draft Folder. This will need modification based on where it's


Set myDraftsFolder = myFolders("[email protected]").Folders("Drafts")

'Loop through all Draft Items

For lDraftItem = myDraftsFolder.Items.count To 1 Step -1

'Check for "To" address and only send if "To" is filled in.

If Len(Trim(myDraftsFolder.Items.Item(lDraftItem).To)) ] 0 Then

'Send Item

myDraftsFolder.Items.Item(lDraftItem).Send

End If
Next lDraftItem

'Clean-up

Set myDraftsFolder = Nothing
Set myNameSpace = Nothing
Set myOutlook = Nothing

End Sub
like image 831
user2032006 Avatar asked Dec 12 '22 13:12

user2032006


2 Answers

I know this is old, but in case someone elses is looking for an answer:

"Active Inline Response" refers to a draft that is open in Outlook. So, when you are debugging, close the draft and flip back to a different message. Then see if your code will run.

like image 166
John Avatar answered Jan 01 '23 17:01

John


I found that if you have clicked on the draft folder so that the Draft folder is active, then you get that error message, usually on the email in the folder that is highlighted.

SOLUTION: Click on any other folder, then run the code, should work, mine did!

like image 26
Ron Cash Avatar answered Jan 01 '23 17:01

Ron Cash