从组合框中替换部分电子邮件正文

时间:2016-02-18 09:09:00

标签: vba combobox outlook-vba

我想从电子邮件中替换正文的一部分,其中包含从下拉列表中选择的值。欢迎任何帮助。

Private Sub UserForm_Initialize()
  With ComboBox1
    .AddItem "Subject 1"
    .AddItem "Subject 2"
    .AddItem "Subject 3"
End With

End Sub
 Private Sub CommandButton1_Click()
    lstNo = ComboBox1.ListIndex
    Unload Me
End Sub

1 个答案:

答案 0 :(得分:2)

如果您打开邮件,则会替换正文中的“测试”。

Private Sub CommandButton1_Click()

    Dim curritem As mailItem

    Set curritem = ActiveInspector.currentItem
    curritem.Body = Replace(curritem.Body, "Test", ComboBox1.Value)

    ' or
    ' curritem.HTMLBody = Replace(curritem.HTMLBody, "Test", ComboBox1.Value)

    Set curritem = Nothing

    Unload Me

End Sub