2013-07-10 34 views
3

我有一個宏以管理電子郵件的,我已經選擇了描述和從模板創建的窗體的填充「消息」字段:如何在發送按鈕單擊時調用宏?

sText = olItem.Body 

Set msg = Application.CreateItemFromTemplate("C:\template.oft") 
With msg 
    .Subject = "Test" 
    .To = "[email protected]" 
    'Set body format to HTML 
    .BodyFormat = Outlook.OlBodyFormat.olFormatHTML 
    .HTMLBody = "<HTML><BODY>EmailDesc: " + sText + "</BODY></HTML>" 
    .Display 
End With 

在這個模板,我有更多的領域以填充,如組合框..例如。

我想知道,當我點擊發送按鈕並在發送之前將它連接到電子郵件的內容時,如何獲得此組合的值?

生成這樣的事情:

EmailDesc: TEST SEND EMAIL BLA BLA BLA.. 
ComboboxValue: Item1 

THX

回答

6

您需要使用Application_ItemSend event當您按下發送按鈕,觸發。您在ThisOutlookSession module中創建此活動。你的事件部分看起來是這樣的:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) 
On Error GoTo ErrorHandler 

    With Item 'Item is your e-mail 
     'this way you could change your subject just before you send message 
     .Subject = "test subject" 
     'here some changes regarding body of the message 
     .Body = .Body & " Additional text at the end or " & _ 
       "ComboBoxValue: " '& ... reference to combobox value here 
    End With 

Exit Sub 
ErrorHandler: 
    MsgBox "Error!" 
End Sub 

是careful-這將使動作到每個電子郵件因此,你應該添加一些if statements,使其只適用於一些你的電子郵件。

+0

我如何獲得選定的組合框值? –