Carl Osbourn
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\M icrosoft\T emplates\T emplate1.o ft"
MakeItem
End Sub
Sub OpenTemplate2()
template = "C:\Users\COsbourn\AppData \Roaming\M icrosoft\T emplates\T emplate2.o ft"
MakeItem
End Sub
Sub OpenTemplate3()
template = "C:\Users\COsbourn\AppData \Roaming\M icrosoft\T emplates\T emplate3.o ft"
MakeItem
End Sub
Sub OpenTemplate4()
template = "C:\Users\COsbourn\AppData \Roaming\M icrosoft\T emplates\T emplate4.o ft"
MakeItem
End Sub
Sub OpenTemplate5()
template = "C:\Users\COsbourn\AppData \Roaming\M icrosoft\T emplates\T emplate5.o ft"
MakeItem
End Sub
Sub OpenTemplate6()
template = "C:\Users\COsbourn\AppData \Roaming\M icrosoft\T emplates\T emplate6.o ft"
MakeItem
End Sub
Sub OpenTemplate7()
template = "C:\Users\COsbourn\AppData \Roaming\M icrosoft\T emplates\T emplate7.o ft"
MakeItem
End Sub
Private Sub MakeItem()
Set newItem = Application.CreateItemFrom Template(t emplate)
newItem.Display
Set newItem = Nothing
End Sub
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
MakeItem
End Sub
Sub OpenTemplate2()
template = "C:\Users\COsbourn\AppData
MakeItem
End Sub
Sub OpenTemplate3()
template = "C:\Users\COsbourn\AppData
MakeItem
End Sub
Sub OpenTemplate4()
template = "C:\Users\COsbourn\AppData
MakeItem
End Sub
Sub OpenTemplate5()
template = "C:\Users\COsbourn\AppData
MakeItem
End Sub
Sub OpenTemplate6()
template = "C:\Users\COsbourn\AppData
MakeItem
End Sub
Sub OpenTemplate7()
template = "C:\Users\COsbourn\AppData
MakeItem
End Sub
Private Sub MakeItem()
Set newItem = Application.CreateItemFrom
newItem.Display
Set newItem = Nothing
End Sub
or maybe
Sub OpenAllTemplates()
For Idx = 1 To 7
template = "C:\Users\COsbourn\AppData\Roaming\Microsoft\Templates\Template" & Idx & ".oft"
MakeItem
Next
End Sub
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?
ASKER
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
ASKER
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
ASKER
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect - all sorted. Thanks Rgonzo1971 :)
pls try
Open in new window
Regards