我在名爲Select_Email_Template的Outlook用戶窗體後面使用了以下代碼。取消按鈕進行選擇而不是取消
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允許用戶選擇電子郵件模板。當選擇一個,並且確定單擊時,模板在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。
如何在沒有此第一個模板的同時打開的情況下關閉表單?
嗨@robinCTS,非常感謝你把它們放在一起並進行解釋。它完美的作品。 非常感謝和親切的問候 – IRHM