Need help modifying a VBA script for emails stuck in Outbox

Legaldeejay

Member
Outlook version
Outlook 2019 64-bit
Email Account
POP3
I found a script online which will allow me to resend emails stuck in the Outbox in Outlook 365. But it requires that I actually go the Outbox folder and select the emails in the Outbox. Is there any way to modify this macro so that when I run it, it will automatically select all emails in the Outbox and apply it? Thanks. This is the VBA script:

Sub BatchResendEmails()
Dim objSelection As Outlook.Selection
Dim objMail As Outlook.MailItem
Dim objInspector As Outlook.Inspector
Dim objResendMail As Outlook.MailItem

Set objSelection = Application.ActiveExplorer.Selection

If Not (objSelection Is Nothing) Then
On Error Resume Next
For Each objMail In objSelection
objMail.Display
Set objInspector = myItem.GetInspector

'Resend message
objInspector.CommandBars.ExecuteMso ("ResendThisMessage")

Set objResendMail = Application.ActiveInspector.CurrentItem

'You can change the email details as per your needs
With objResendMail
.Subject = objMail.Subject
.Send
End With

objMail.Close olDiscard
Next
End If
End Sub
 

Legaldeejay

Member
Outlook version
Outlook 2019 64-bit
Email Account
POP3
I found a script online which will allow me to resend emails stuck in the Outbox in Outlook 365. But it requires that I actually go the Outbox folder and select the emails in the Outbox. Is there any way to modify this macro so that when I run it, it will automatically select all emails in the Outbox and apply it? Thanks. This is the VBA script:

Sub BatchResendEmails()
Dim objSelection As Outlook.Selection
Dim objMail As Outlook.MailItem
Dim objInspector As Outlook.Inspector
Dim objResendMail As Outlook.MailItem

Set objSelection = Application.ActiveExplorer.Selection

If Not (objSelection Is Nothing) Then
On Error Resume Next
For Each objMail In objSelection
objMail.Display
Set objInspector = myItem.GetInspector

'Resend message
objInspector.CommandBars.ExecuteMso ("ResendThisMessage")

Set objResendMail = Application.ActiveInspector.CurrentItem

'You can change the email details as per your needs
With objResendMail
.Subject = objMail.Subject
.Send
End With

objMail.Close olDiscard
Next
End If
End Sub
I meant to add that I have 2 accounts, including a Microsoft Exchange account. Is there any way to modify this macro so that when I send any email in the Microsoft Exchange account, all emails are automatically selected in the Outbox which may be stuck and the below macro is run in the Outbox?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Oh wait, you need the current item not the current folder - you will need to get the items - loop all messages in the folder.

Set objResendMail = Session.GetDefaultFolder(olFolderOutbox)

This shows how to get other folders-

This have two macros - one works on all items in the folder. This is what you need to use, changing it from current folder to the outbox.
I meant to add that I have 2 accounts, including a Microsoft Exchange account. Is there any way to modify this macro so that when I send any email in the Microsoft Exchange account, all emails are automatically selected in the Outbox which may be stuck and the below macro is run in the Outbox?
Are the messages stuck because they are turning into drafts?
 

Legaldeejay

Member
Outlook version
Outlook 2019 64-bit
Email Account
POP3
They are getting stuck because I am using an Add-In for work which is not working correctly and causing the messages to be stuck in the Outbox. I got it to work using this code as suggested by somebody else in another forum, but now I am trying to figure out how to run this script automatically whenever I click Send to send an email. Any suggestions?

Sub BatchResendEmails()
Dim objFolder As Outlook.MAPIFolder
Dim objMail As Outlook.MailItem
Dim objInspector As Outlook.Inspector
Dim objResendMail As Outlook.MailItem

Set objFolder = Application.Session.GetDefaultFolder(olFolderOutbox)

On Error Resume Next
For Each objMail In objFolder.Items
objMail.Display
Set objInspector = myItem.GetInspector

'Resend message
objInspector.CommandBars.ExecuteMso ("ResendThisMessage")

Set objResendMail = Application.ActiveInspector.CurrentItem

'You can change the email details as per your needs
With objResendMail
.Subject = objMail.Subject
.Send
End With

objMail.Close olDiscard
Next
End Sub
 

Legaldeejay

Member
Outlook version
Outlook 2019 64-bit
Email Account
POP3
Alternatively, I would like to schedule the script to run periodically (i.e. every 5 minutes) using Windows Task Scheduler or running a batch file. I appreciate your assistance.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
PowerShell would work better for running in task scheduler.... but you can run macros when a reminder fires as outlook doesn't have a timer function.

Do you want to check all messages in the folder when you send a message or just the one you just sent?

Itemsend macros use a title like this:
Sub Application_ItemSend(objMail As Outlook.MailItem)

and applies to the message just sent.
This article has some examples- you would need to replace the code with your macro, tweaking it as needed.


Running every 5 with a reminder might be the best - it will work with either task or appointment reminders
 
Similar threads
Thread starter Title Forum Replies Date
Marc2019 Need help please! Cannot Setup my outlook email account on my Mac Outlook 2011 Using Outlook.com accounts in Outlook 2
C need help setting up outlook first time Using Outlook 1
N Need help syncing contacts to iPhone X Using Outlook 8
S Error using AddressEntry.GetContact - need help Outlook VBA and Custom Forms 2
EaglePI Outlook 2010 need help with rules Using Outlook 0
B Need Help - Willing to pay Outlook VBA and Custom Forms 10
J Need Help with Contacts VBA Outlook VBA and Custom Forms 1
H Need help setting up GetFolderPath-Makro with Vodafone IMAP Mail-Account Outlook VBA and Custom Forms 0
T Need help with finding/updating task Outlook VBA and Custom Forms 1
Denis Hi everyone!!! Need some help with Excel to Exchange Calendar??PLEASE>>> Using Outlook 1
E Need Help on Setting up a repeated Reminder on Task with Reoccurence Every Year Using Outlook 6
B Need Help Creating Email Based on Subject w Address in Body Outlook VBA and Custom Forms 1
G Need help configuring a PRF for Outlook 2010 and 2013 Using Outlook 0
K Excel Import Option: Need Help Updating Existing Records BCM (Business Contact Manager) 0
K Need help concerning emails linking to BCM. BCM (Business Contact Manager) 0
J Need help with installation of BCM in Outlook2013 BCM (Business Contact Manager) 5
F Outlook 2010 - Need help with a custom field. Using Outlook 3
D Need Help with Script. Keep getting Runtime Error 438 BCM (Business Contact Manager) 4
R Need help getting BCM to work with my Outlook 2014 Using Outlook 4
L Need help getting calendar/contacts/tasks/notes back! Using Outlook 3
R [VBA] complicated(?) outlook events - need help with code Using Outlook 15
P Need help/Gmail accounts show separately/Outlook 2013 Using Outlook 0
J Need Help Extracting Email Content into Excel Specifically the Attachment Name Using Outlook 3
A Need Help with BCM2010 Sharing on outlook 2013 Scenario! BCM (Business Contact Manager) 1
C Need Help with Simple Code Correction Using Outlook 11
W I Need help with vb.net and outlook 2010 Using Outlook 2
A My move to MS is not going too well: Need Help !!! Using Outlook 14
M Need help with combo boxes in messages! Using Outlook 10
D Need help understanding which pst-file to use! Using Outlook 0
U Need a help please Outlook 2007 crashing Using Outlook 2
Z Need Help Outlook 2007 inbox and address book view Using Outlook 2
B Need help adding a background color to the compact list items in Month view. Calendar Printing Assistant 1
B Need help adding an image next to the Month Name in the header. Calendar Printing Assistant 1
B Ok - a complicated one - but really need help (auto formatting) Using Outlook 9
B OUTLOOK 2000, Need Help ! Outlook Wishlist 1
P To Use BCM or not...I need help BCM (Business Contact Manager) 1
T Need help making RULE to prepend email SUBJECT Using Outlook 3
V Need help on configuring Outook 2003 Rules and Alerts... Using Outlook 2
X business owner in dire need of help outlook is not syncin my contacts! Using Outlook.com accounts in Outlook 2
D Need email verification for international emails, help? BCM (Business Contact Manager) 2
S MAcro - Need help in getting the recipients in to filed / cc field toput in an array Outlook VBA and Custom Forms 4
K Need help Publishing a new Task form! Outlook VBA and Custom Forms 1
A Need help in creating a mass emailing plugin Outlook VBA and Custom Forms 1
T need help w/ sending an e-mail -- outlook 2007 addin Outlook VBA and Custom Forms 2
K Need to convert .mmf file to .pst format Outlook VBA and Custom Forms 7
glnz Moving from Outlook 2003 to MS365 Outlook - need basics Using Outlook 4
J Moved many emails to Outlook external folder, need to delete on Gmail server Using Outlook 14
A Wishlist Arthur workman I need the community's assistance thank you Using Outlook 4
A from Arthur to anyone I need your expertise assistance Using Outlook.com accounts in Outlook 7
T Need to backup outlook.com to cloud storage, without desktop software - Testing UpSafe. Are there any similar services? Using Outlook.com accounts in Outlook 8

Similar threads

Top