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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,223,882
Messages
6,175,165
Members
452,615
Latest member
bogeys2birdies

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