Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to send email to recipient selected from a combo box ?

Status
Not open for further replies.

iboumiza

Programmer
Jul 16, 2011
2
CA
Hi everybody,

I basically use this simple code that send automatically emails without opening Outlook window for it.

VBA:
Sub SendVBAMail()

Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem

On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
If OutApp Is Nothing Then
Set OutApp = CreateObject("Outlook.Application")
End If
On Error Goto 0

Set OutMail = OutApp.CreateItem(olMailItem)

With OutMail
.To = "name@domain.com"
.Subject = "This is the Subject line"
.Body = "Hi there"
.Send
End With

Set OutMail = Nothing
Set OutApp = Nothing

End Sub

What I'm looking for is:
How to send the email to a specific person selected from a combo box ?
I know that it's .To = "name@domain.com" that must be changed but I don't know how to make it look for a value in a combo box?!

Any help would be really appreciated!

Sincerly
iboumiza
 

If you have in your combo box (cboMyCombo) something like:[tt]
name@domain.com
bob@msn.com
gates@microSoft.com[/tt]

you may simply do:
Code:
    With OutMail 
        .To = [blue]cboMyCombo.Text [/blue]
        .Subject = "This is the Subject line" 
        .Body = "Hi there" 
        .Send 
    End With

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top