Populating ComboBoxes VBA


Solution 1

Try this:

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


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

Solution 2

Sub emailfromexcel()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
    .To = "[email protected]"
    .BCC = thebcc
    .Subject = "This subject"
    .Body = "This body"
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Author by


Updated on June 25, 2020


  • Mônica
    Mônica over 2 years

    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>"
        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...

  • Mônica
    Mônica over 9 years
    same error: "object doesn't support this property or method" =/
  • Grant
    Grant over 9 years
    This got me curious, so I started some reading. It says to use a with/end for combobox and additem. I was doing it with Access thinking it might work the same. Maybe try the edited code.