VBA Email Templates

Shazzaz

New Member
Joined
Aug 28, 2024
Messages
5
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Hi All,
I have a VBA script that opens templates from my drafts folder in outlook, I'm struggling to work out how I can get it to get the templates from a file on my C: drive instead of my drafts folder........

this is what I use now within outlook - it works perfectly I just want to be able to change where it gets the template from - thanks in advance!!!

Private Const TemplateFolder As String = "My Templates"

Public Sub Draft_1()
LoadTemplate "New Proposal"
End Sub

Private Sub LoadTemplate(Name As String)
Dim Ns As Outlook.NameSpace
Dim Folder As Outlook.MAPIFolder
Dim Mail As Outlook.MailItem

Set Ns = Application.GetNamespace("MAPI")
Set Folder = Ns.GetDefaultFolder(olFolderDrafts)
Set Folder = Folder.Folders(TemplateFolder)
Set Mail = LoadTemplate_Ex(Folder.Items, Name)
If Not Mail Is Nothing Then
Mail.Display
Else
MsgBox "No template with the subject: '" & Name & "' found"
End If
End Sub

Private Function LoadTemplate_Ex(Items As Outlook.Items, Name As String) As Outlook.MailItem
On Error Resume Next
Dim Mail As Outlook.MailItem
Set Mail = Items.Find("[subject]=" & Chr(34) & Name & Chr(34))
If Not Mail Is Nothing Then
Set LoadTemplate_Ex = Mail.Copy
End If
End Function
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,222,903
Messages
6,168,939
Members
452,227
Latest member
sam1121

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