Link to home
Start Free TrialLog in
Avatar of Carl Osbourn
Carl OsbournFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Using Outlook VBA to Open Multiple Templates in one String

Hi!

I have created 7 templates that I would like to write a Macro for that opens them all in succession for me to manually insert attachments and send.  After trawling a few forums I have cobbled this together however I am now struggling to see what I am missing in order to make this work once assigned to a toolbar button:

Dim template As String

Sub OpenTemplate1()
template = "C:\Users\COsbourn\AppData\Roaming\Microsoft\Templates\Template1.oft"
MakeItem
End Sub

Sub OpenTemplate2()
template = "C:\Users\COsbourn\AppData\Roaming\Microsoft\Templates\Template2.oft"
MakeItem
End Sub

Sub OpenTemplate3()
template = "C:\Users\COsbourn\AppData\Roaming\Microsoft\Templates\Template3.oft"
MakeItem
End Sub

Sub OpenTemplate4()
template = "C:\Users\COsbourn\AppData\Roaming\Microsoft\Templates\Template4.oft"
MakeItem
End Sub

Sub OpenTemplate5()
template = "C:\Users\COsbourn\AppData\Roaming\Microsoft\Templates\Template5.oft"
MakeItem
End Sub

Sub OpenTemplate6()
template = "C:\Users\COsbourn\AppData\Roaming\Microsoft\Templates\Template6.oft"
MakeItem
End Sub

Sub OpenTemplate7()
template = "C:\Users\COsbourn\AppData\Roaming\Microsoft\Templates\Template7.oft"
MakeItem
End Sub

Private Sub MakeItem()
Set newItem = Application.CreateItemFromTemplate(template)
newItem.Display
Set newItem = Nothing
End Sub
Avatar of Rgonzo1971
Rgonzo1971

Hi,

pls try
Sub OpenAllTemplates()
Call OpenTemplate1
Call OpenTemplate2
Call OpenTemplate3
Call OpenTemplate4
Call OpenTemplate5
Call OpenTemplate6
Call OpenTemplate7
End Sub

Open in new window

Regards
or maybe
Sub OpenAllTemplates()
For Idx = 1 To 7
    template = "C:\Users\COsbourn\AppData\Roaming\Microsoft\Templates\Template" & Idx & ".oft"
    MakeItem
Next
End Sub

Open in new window

Avatar of Carl Osbourn

ASKER

Thanks, Rgonzo1971 - that doesn't seem to do anything.  Where am I specifying the *.oft template files there?
Have you tried my second attempt?
Yes - it states "Compile error: Sub or Function not defined" and highlights "MakeItem"
then try
Sub OpenAllTemplates()
For Idx = 1 To 7
    template = "C:\Users\COsbourn\AppData\Roaming\Microsoft\Templates\Template" & Idx & ".oft"
    MakeItem
Next
End Sub

Private Sub MakeItem(tmplt as String)
Set newItem = Application.CreateItemFromTemplate(tmplt)
newItem.Display
Set newItem = Nothing
End Sub

Open in new window

Thanks - its now saying "Compile error: Argument not optional"
Sorry
Sub OpenAllTemplates()
For Idx = 1 To 7
    template = "C:\Users\COsbourn\AppData\Roaming\Microsoft\Templates\Template" & Idx & ".oft"
    MakeItem template
Next
End Sub
Private Sub MakeItem(ByVal tmplt As String)
Set newItem = Application.CreateItemFromTemplate(tmplt)
newItem.Display
Set newItem = Nothing
End Sub

Open in new window

Thanks Rgonzo1971 - I think we're there!

One further question, is there a way to modify this slightly so that the created emails are saved in drafts?  Or at least presented with the "Do you want to save changes?" dialog box which enables you to save them into drafts?

Currently, if I close them they just close without prompting to save.
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect - all sorted.  Thanks Rgonzo1971 :)