我正在使用以下代码,用于 Outlook UserForm Select_Email_Template 的后台。
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "Account Amendment Non SC"
.AddItem "Account Amendment SC Application Received"
.AddItem "Account Amendment SC"
.AddItem "Account Creation Non SC"
.AddItem "Account Creation SC Application Received"
.AddItem "Account Creation SC"
.AddItem "Export Function"
.AddItem "Password Reset"
End With
End Sub
Private Sub btnOK_Click()
lstNum = ComboBox1.ListIndex
Unload Me
End Sub
Private Sub btnCancel_Click()
Unload Select_Email_Template
End Sub
ComboBox允许用户选择电子邮件模板。当用户选择了一个模板并点击OK时,该模板将在Outlook中打开。
以下是打开模板的代码:
Public lstNum As Long
Public Sub Email_Templates()
Dim outMail As Outlook.MailItem
Select_Email_Template.Show
Select Case lstNum
' Following the listbox entries
Case 0
Set outMail = CreateItemFromTemplate("TemplatePath\Account Amendment Non SC.oft")
Case 1
Set outMail = CreateItemFromTemplate("TemplatePath\Account Amendment SC Application Received.oft")
Case 2
Set outMail = CreateItemFromTemplate("TemplatePath\Account Amendment SC.oft")
Case 3
Set outMail = CreateItemFromTemplate("TemplatePath\Account Creation Non SC.oft")
Case 4
Set outMail = CreateItemFromTemplate("TemplatePath\Account Creation SC Application Received.oft")
Case 5
Set outMail = CreateItemFromTemplate("TemplatePath\Account Creation SC.oft")
Case 6
Set outMail = CreateItemFromTemplate("TemplatePath\Export Function.oft")
Case 7
Set outMail = CreateItemFromTemplate("TemplatePath\Export Function.oft")
End Select
' Use for a specific purpose not randomly
' On Error Resume Next
With outMail
.Display
End With
' On Error GoTo 0
cleanup:
Set outMail = Nothing
End Sub
当用户点击取消时,表单将关闭,但是在Outlook中将打开列表中的第一个模板。
如何在不同时打开第一个模板的情况下关闭表单?