VBA for sending all emails in outlook draft folder

Moustafa Houssien

New Member
Joined
Jul 7, 2023
Messages
5
Hi,
I need support for knowing the problem in the below code as the error message "Run-Time Error '13':type mismatched" appeared

Sub SendAllDraftEmails()

'Declare variables
Dim objOutlook As Outlook.Application
Dim objFolder As Outlook.MAPIFolder
Dim objMail As Outlook.MailItem
Dim lCounter As Long

'Get the Outlook application object
Set objOutlook = Application

'Get the draft folder
Set objFolder = objOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)

'Initialize the counter
lCounter = 1

'Loop through all the items in the draft folder
For Each objMail In objFolder.Items

'Send the email
objMail.Send

'Increment the counter
lCounter = lCounter + 1

Next objMail

'Display a message box
MsgBox "Sent " & lCounter & " emails"

End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try this
VBA Code:
Sub SendAllDraftEmails()

'Declare variables
'Dim objOutlook As Outlook.Application
Dim ol As Object
Dim objOutook As Application
Set ol = CreateObject("Outlook.Application")
Set objOutlook = ol

Dim objFolder As Outlook.MAPIFolder
Dim objMail As Outlook.MailItem
Dim lCounter As Long

'Get the Outlook application object
Set objOutlook = Application

'Get the draft folder
Set objFolder = objOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)

'Initialize the counter
lCounter = 1

'Loop through all the items in the draft folder
For Each objMail In objFolder.Items

'Send the email
objMail.Send

'Increment the counter
lCounter = lCounter + 1

Next objMail

'Display a message box
MsgBox "Sent " & lCounter & " emails"

End Sub
 
Upvote 0
Try this
VBA Code:
Sub SendAllDraftEmails()

'Declare variables
'Dim objOutlook As Outlook.Application
Dim ol As Object
Dim objOutook As Application
Set ol = CreateObject("Outlook.Application")
Set objOutlook = ol

Dim objFolder As Outlook.MAPIFolder
Dim objMail As Outlook.MailItem
Dim lCounter As Long

'Get the Outlook application object
Set objOutlook = Application

'Get the draft folder
Set objFolder = objOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)

'Initialize the counter
lCounter = 1

'Loop through all the items in the draft folder
For Each objMail In objFolder.Items

'Send the email
objMail.Send

'Increment the counter
lCounter = lCounter + 1

Next objMail

'Display a message box
MsgBox "Sent " & lCounter & " emails"

End Sub
Thanks it works but stopped in the below line
Set objFolder = objOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)

Run-time error '438' :Object doesn't support this property or method

Thanks for your support
 

Attachments

  • Run-time error 438.png
    Run-time error 438.png
    5.5 KB · Views: 5
Upvote 0
See if this works. Apologies for the uncertainty, but I normally don't call other Office Applications in my Excel VBA.
VBA Code:
Sub SendAllDraftEmails()

'Declare variables
'Dim objOutlook As Outlook.Application
'Dim ol As Object
'Dim objOutook As Application
'Set ol = CreateObject("Outlook.Application")
'Set objOutlook = ol

Dim objFolder As Outlook.MAPIFolder
Dim objMail As Outlook.MailItem
Dim lCounter As Long

'Get the Outlook application object
'Set objOutlook = Application

SHELL ("Outlook")

'Get the draft folder
Set objFolder = objOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)

'Initialize the counter
lCounter = 1

'Loop through all the items in the draft folder
For Each objMail In objFolder.Items

'Send the email
objMail.Send

'Increment the counter
lCounter = lCounter + 1

Next objMail

'Display a message box
MsgBox "Sent " & lCounter & " emails"

End Sub
 
Upvote 0
See if this works. Apologies for the uncertainty, but I normally don't call other Office Applications in my Excel VBA.
VBA Code:
Sub SendAllDraftEmails()

'Declare variables
'Dim objOutlook As Outlook.Application
'Dim ol As Object
'Dim objOutook As Application
'Set ol = CreateObject("Outlook.Application")
'Set objOutlook = ol

Dim objFolder As Outlook.MAPIFolder
Dim objMail As Outlook.MailItem
Dim lCounter As Long

'Get the Outlook application object
'Set objOutlook = Application

SHELL ("Outlook")

'Get the draft folder
Set objFolder = objOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)

'Initialize the counter
lCounter = 1

'Loop through all the items in the draft folder
For Each objMail In objFolder.Items

'Send the email
objMail.Send

'Increment the counter
lCounter = lCounter + 1

Next objMail

'Display a message box
MsgBox "Sent " & lCounter & " emails"

End Sub
Nevermind. It doesn't work.
 
Upvote 1
See if this works. Apologies for the uncertainty, but I normally don't call other Office Applications in my Excel VBA.
VBA Code:
Sub SendAllDraftEmails()

'Declare variables
'Dim objOutlook As Outlook.Application
'Dim ol As Object
'Dim objOutook As Application
'Set ol = CreateObject("Outlook.Application")
'Set objOutlook = ol

Dim objFolder As Outlook.MAPIFolder
Dim objMail As Outlook.MailItem
Dim lCounter As Long

'Get the Outlook application object
'Set objOutlook = Application

SHELL ("Outlook")

'Get the draft folder
Set objFolder = objOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)

'Initialize the counter
lCounter = 1

'Loop through all the items in the draft folder
For Each objMail In objFolder.Items

'Send the email
objMail.Send

'Increment the counter
lCounter = lCounter + 1

Next objMail

'Display a message box
MsgBox "Sent " & lCounter & " emails"

End Sub
Thanks I will try it
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,139
Members
449,098
Latest member
Doanvanhieu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top