填充ComboBoxes VBA

时间:2013-06-21 12:00:29

标签: vba outlook outlook-vba

我有这个VBA代码:

Sub sendByCustomForm()
Dim olItem As Outlook.MailItem
Dim sText As String

If Application.ActiveExplorer.Selection.Count = 0 Then
    MsgBox "No Items selected!", vbCritical, "Error"
    Exit Sub
End If

For Each olItem In Application.ActiveExplorer.Selection
    sText = olItem.Body

    Set msg = Application.CreateItemFromTemplate("C:\myCustomForm.oft")
    MsgBox sText, vbInformation, "alert"

    With msg
        'Set body format to HTML
        .BodyFormat = Outlook.OlBodyFormat.olFormatHTML
        .HTMLBody = "<HTML><BODY>" + sText + "</BODY></HTML>"
        .Display
    End With
Next olItem    
End Sub

该模板有2个我想填充的组合框,但我该怎么办呢?

当我尝试这个时:

msg.ComboBox1.AddItem "item"

它不起作用......

2 个答案:

答案 0 :(得分:1)

试试这个:

'For Access
msg.ComboBox1.RowSource = msg.ComboBox1.Rowsource & ";'item'"

更新

With ComboBox        
.AddItem "Option 1"        
.AddItem "Option 2"        
.AddItem "Option 3"
End With

答案 1 :(得分:1)

Sub emailfromexcel()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
    .To = "person@email.com"
    .BCC = thebcc
    .Subject = "This subject"
    .Body = "This body"
    .Display
    .Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub