我想創建一個Outlook Userform,通過下拉菜單中的操作員可以選擇一個電子郵件模板。從Userform下拉菜單中選擇電子郵件模板 - 對象是必需的
使用this示例,這是Outlook表單的代碼,可正常工作。
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "Test"
.AddItem "Template 2"
.AddItem "Template 3"
.AddItem "Template 7"
.AddItem "Template 5"
.AddItem "Template 6"
End With
End Sub
Private Sub btnOK_Click()
lstNum = ComboBox1.ListIndex
Unload Me
End Sub
這是我已經開始放在一起,選擇模板的代碼。當我使用下拉菜單選擇「測試模板」時,我收到一個錯誤,這裏「Test.Select」突出顯示一個對象是必需的。
Public lstNum As Long
Public Sub ChooseTemplate()
Dim oMail As Outlook.MailItem
Dim oContact As Outlook.ContactItem
Dim strTemplate As String
UserForm1.Show
Select Case lstNum
Case -1
' -1 is what you want to use if nothing is 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
With OutMail
.To = cell.Value
.Subject = "Test Facility"
.HTMLBody = "<BODY style=font-size:11pt;font-family:Calibri>Hi " You recently confirmed you require continued use of the test facility
"<p>Many thanks and kind regards</p></BODY>" & Signature
.Sensitivity = 2
.Send
End With
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
和這個'Test'應該是什麼?它在哪裏被聲明和初始化(你使用它的方式表明它是一個對象) – avb
嗨@avb,謝謝你花時間回到我身邊。測試是我的模板的名稱,但使用下面的niton的解決方案,我已經能夠得到這個工作。 非常感謝和問候 克里斯 – IRHM