Need help modifying a VBA script for emails stuck in Outbox

Status
Not open for further replies.

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 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?
 
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?
 
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
 
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.
 
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
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
FryW Need help modifying a VBA script for in coming emails to auto set custom reminder time Outlook VBA and Custom Forms 0
S Custom Contact card - need help creating one Outlook VBA and Custom Forms 1
D Need help with MS Authenticator Using Outlook 4
I Outlook for Mac 2019 using on desktop and laptop IMAP on both need help with folders Using Outlook 1
S.Champ Please help? I've imported a random workcalendar I dont even know who's. Can I undo it? and then I need to re-sync the google one again. Its a mess:( Using Outlook 2
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
E 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. Using Outlook 1
B Need help adding an image next to the Month Name in the header. Using Outlook 1
B Ok - a complicated one - but really need help (auto formatting) Using Outlook 9
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
e_a_g_l_e_p_i Need clarification on 2-Step Verification for Gmail using Outlook 2021 Using Outlook 10
P OT: Need website like this one, but for Excel Using Outlook 0

Similar threads

Back
Top