Populating ComboBoxes VBA

泄露秘密 提交于 2019-12-11 03:07:54

问题


I have this VBA code:

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

That template has 2 ComboBoxes that I want to populate, but how can I do this?

When I try this:

msg.ComboBox1.AddItem "item"

it doesn't work...


回答1:


Try this:

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

Update:

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



回答2:


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


来源:https://stackoverflow.com/questions/17234742/populating-comboboxes-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!