Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delaying a batch of emails in Outlook Drafts folder.

Status
Not open for further replies.

IcarusHallsorts

Technical User
Nov 8, 2019
9
GB
A third party application produces batches of emails for me and puts them in the Drafts folder for me to send. Thanks to the ingenuity of fellow Tek-Tips users, I have developed macros which, when I have selected one or more messages, can add specific cc/bcc addresses to them and or send them as a batch.
My next challenge is to be able to make a selection of draft emails form the folder, and then schedule them for sending at a later date. Perhaps a date picker could pop up once the macro starts to run, and the selected date and time would be assigned to the specific messages which would be sent as required. Or even one where there is a user prompt asking for how many days/hours the sending should be delayed for.
Any ideas how this could be accomplished with Outlook VBA?
 
Certainly, you can achieve your goal of scheduling draft emails for sending at a later date using Outlook VBA. Here's a high-level guide on how to implement this functionality:

1. **Create a Macro-Enabled Module**:
Open Outlook, press `Alt + F11` to open the Visual Basic for Applications (VBA) editor. Create a new module by clicking "Insert" > "Module."

2. **Write the VBA Code**:
In the module you've created, write the VBA code to achieve the scheduling functionality. Below is a basic example code that demonstrates how to prompt the user for a delay period and then schedule the selected drafts for sending:

```vba
Sub ScheduleDraftsForSending()
Dim selectedItems As Selection
Dim draftItem As MailItem
Dim delayPeriod As Variant
Dim sendTime As Date

Set selectedItems = Application.ActiveExplorer.Selection

If selectedItems.Count = 0 Then
MsgBox "No items selected."
Exit Sub
End If

delayPeriod = InputBox("Enter delay period in hours:", "Schedule Drafts for Sending")

If Not IsNumeric(delayPeriod) Then
MsgBox "Invalid input."
Exit Sub
End If

For Each draftItem In selectedItems
If draftItem.Class = olMail Then
sendTime = Now + TimeValue(delayPeriod & ":00:00")
draftItem.DeferredDeliveryTime = sendTime
draftItem.Send
End If
Next draftItem
End Sub
```

3. **Adjust the Code**:
You can modify the code to better suit your needs. For example, you could use a date picker control to allow the user to select a specific date and time, or you can use the provided delay period as hours. You might want to add error handling to handle invalid input or other unexpected situations.

4. **Run the Macro**:
Close the VBA editor and return to Outlook. You can add this macro to your Quick Access Toolbar or ribbon so you can easily run it when needed. To do this, right-click on the ribbon or Quick Access Toolbar, select "Customize Quick Access Toolbar" > "More Commands," choose "Macros" from the drop-down, and add your macro.

Remember that macros can have security implications, so it's important to only run macros from sources you trust and to enable macros with caution.

This code is a starting point, and you can customize and enhance it based on your specific requirements. If you're not familiar with VBA programming, you might want to consult Outlook VBA documentation or seek assistance from experienced VBA developers.

Link
 
Thanks for your reply and apologies for the apparant delay in responding - I have only just seen it. I tried using the code, entering the number of hours as an integer - the macro would not run with hours expressed as a decomal or in hh::mm format.
The macro incurred a runtime error; -2147467259 (80004005) stating "his method can't be used with inline response email item."
Is there alternative method you are aware of?
Many thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top