Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-15-2021, 05:13 AM
JamesWood JamesWood is offline Send selected drafts VBA Windows 10 Send selected drafts VBA Office 2019
Novice
Send selected drafts VBA
 
Join Date: Nov 2020
Posts: 16
JamesWood is on a distinguished road
Question Send selected drafts VBA

Hi guys


I've seen a lot of complicated VBAs to achieve sending selected drafts, however I'm working on this at the moment... I'm stuck at this part that's not working:




For Each Draftmail In xSelection
Draftmail.Send
Next


Any thoughts would be really welcome! Full code is below.


Thanks
James


Sub SendSelectedDraftEmails()
Dim xSelection As Selection
Dim xPromptStr As String
Dim xYesOrNo As Integer
Dim i As Long
Set xSelection = Outlook.Application.ActiveExplorer.Selection

If xSelection.count > 0 Then
xPromptStr = "Are you sure to send the selected " & xSelection.count & " draft item(s)?"
xYesOrNo = MsgBox(xPromptStr, vbQuestion + vbYesNo)
If xYesOrNo = vbYes Then

For i = xSelection.count To 1 Step -1

For Each Draftmail In xSelection
Draftmail.Send
Next

Next
MsgBox "Successfully sent " & xSelection.count & " messages"
End If
Else
MsgBox "No drafts selected!"
End If

End Sub
Reply With Quote
  #2  
Old 02-19-2021, 03:48 AM
JamesWood JamesWood is offline Send selected drafts VBA Windows 10 Send selected drafts VBA Office 2019
Novice
Send selected drafts VBA
 
Join Date: Nov 2020
Posts: 16
JamesWood is on a distinguished road
Default

Hi guys


Nevermind the above, I've come up with a workaround. Essentially I have ended up with a macro that sends all the drafts in a particular drafts folder (in this case, Merge Tools). I was also getting an 'inline' error whilst using this because I was viewing the draft it was trying to send, so I made it switch to the Inbox view before sending the drafts. Here's the code for anyone who wants it


Sub SendAllMergeToolsDrafts()

If MsgBox("Are you sure you want to send ALL the items in your Merge Tools drafts folder?", _
vbQuestion + vbYesNo) <> vbYes Then Exit Sub

Dim myNamespace As Outlook.NameSpace 'Change view to Inbox to avoid inline error
Set myNamespace = Application.GetNamespace("MAPI") 'Change view to Inbox to avoid inline error
Set Application.ActiveExplorer.CurrentFolder = _
myNamespace.GetDefaultFolder(olFolderInbox) 'Change view to Inbox to avoid inline error

Dim fldDraft As MAPIFolder, msg As Outlook.MailItem, intCount As Integer
Set fldDraft = Outlook.GetNamespace("MAPI").GetDefaultFolder(olFo lderDrafts).Folders("Merge Tools") 'Sends all drafts in the Merge Tools folder only
intCount = 0
Do While fldDraft.Items.count > 0
Set msg = fldDraft.Items(1)
msg.Send
intCount = intCount + 1
Loop
If Not (msg Is Nothing) Then Set msg = Nothing
Set fldDraft = Nothing
MsgBox intCount & " messages sent", vbInformation + vbOKOnly

End Sub
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to change 'From' on drafts JamesWood Outlook 5 02-15-2021 05:10 AM
word 2016 won't change to drafts for default view infonutt Word 0 07-21-2017 10:31 AM
Send selected drafts VBA My draft message gets deleted from drafts when I send it? Bansaw Outlook 2 07-28-2011 08:45 AM
autosaving drafts with digital signature in outlook 2010 lvovich Outlook 0 04-11-2011 12:40 AM
Sent Items in Saved in Drafts trish@25by7.com Outlook 1 11-05-2010 02:33 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 06:54 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft