Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

Error '438': Object doesn't support this property or method when running Outlook from Excel VBA

$
0
0

I'm trying to get Outlook to fetch a mail template I have stored in the folder "Templates" from a Excel VBA code, but get the error 438 code on the line "Mapp = Application.GetNamespace..." in the GetMailTemplate-function.

I have added both Microsoft Office 16.0 Object Library & Microsoft Outlook 16.0 Object Library to Excel VBAProject

This is my code:

Sub Email()
Dim AMailItem As Outlook.MailItem
Set AMailItem = GetMailTemplate("Mall Confidential")
With AMailItem
    .To = "a.b@c.com"
    .Subject = "Email Test using VBA"
    .Body = "Test"
    .Display
    .Send
End With   
Set AMailItem = Nothing
End Sub

Function GetMailTemplate(Headline As String) As Outlook.MailItem
Dim Mapp As Outlook.Folder
Dim OutMail2 As Outlook.MailItem
Mapp = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts).Folders("Templates")
For Each OutMail2 In Mapp.Items                 
    Debug.Print OutMail2.Subject                    'Print to immediate window
    If OutMail2.Subject = Headline Then             
        Set GetMailTemplate = OutMail2.Copy         
        Exit Function
    End If
Next
End Function

Viewing all articles
Browse latest Browse all 88835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>