2

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

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Mônica
  • 97
  • 2
  • 2
  • 7

2 Answers2

2

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
Grant
  • 903
  • 1
  • 16
  • 24
  • same error: "object doesn't support this property or method" =/ – Mônica Jun 21 '13 at 12:23
  • 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. – Grant Jun 21 '13 at 12:40
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