vba - Outlook Form To Select Email Template -
i wonder whether may able me please.
i'm trying create outlook userform, via drop down menu operator can select email template.
using this example, code outlook form works fine.
private sub userform_initialize() combobox1 .additem "test" .additem "template 2" .additem "template 3" .additem "template 7" .additem "template 5" .additem "template 6" end end sub private sub btnok_click() lstnum = combobox1.listindex unload me end sub this code i've started put together, select template having had no experience of before when use drop down menu , select "test template" receive error here "test.select" highlighting object required.
public lstnum long public sub choosetemplate() dim omail outlook.mailitem dim ocontact outlook.contactitem dim strtemplate string userform1.show select case lstnum case -1 ' -1 want use if nothing selected strtemplate = "test" case 0 strtemplate = "template-1" case 1 strtemplate = "template-2" case 2 strtemplate = "template-3" case 3 strtemplate = "template-4" case 4 strtemplate = "template-5" end select test.select set outmail = outapp.createitem(0) on error resume next outmail .to = cell.value .subject = "test facility" .htmlbody = "<body style=font-size:11pt;font-family:calibri>hi " confirmed require continued use of test facility "<p>many , kind regards</p></body>" & signature .sensitivity = 2 .send end on error goto 0 set outmail = nothing cleanup: set outapp = nothing application.screenupdating = true wb.close savechanges:=true end if set omail = nothing end sub i wondered whether @ please , let me know i've gone wrong.
to generate mail template see https://msdn.microsoft.com/vba/outlook-vba/articles/application-createitemfromtemplate-method-outlook
set myitem = application.createitemfromtemplate("c:\statusrep.oft") run code in outlook see how use selection.
public lstnum long public sub choosetemplate() dim outmail outlook.mailitem userform1.show select case lstnum ' following listbox entries case -1 ' -1 want use if nothing selected set outmail = createitemfromtemplate("path\to\test.oft") case 0 set outmail = createitemfromtemplate("path\to\test.oft") case 1 set outmail = createitemfromtemplate("path\to\template-2.oft") case 2 set outmail = createitemfromtemplate("path\to\template-3.oft") case 3 set outmail = createitemfromtemplate("path\to\template-7.oft") case 4 set outmail = createitemfromtemplate("path\to\template-5.oft") case 5 set outmail = createitemfromtemplate("path\to\template-6.oft") end select ' use specific purpose not randomly ' on error resume next outmail .to = "cell.value" ' outlook demo ' should in template ' .subject = "test facility" ' .htmlbody = "<body style=font-size:11pt;font-family:calibri>hi " confirmed require continued use of test facility ' "<p>many , kind regards</p></body>" & signature ' .sensitivity = 2 .display end ' on error goto 0 cleanup: set outmail = nothing end sub
Comments
Post a Comment