View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Auto email from excel with custom subject

You can use a label or textbox like this in the code of a button on the userform


Private Sub CommandButton1_Click()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail
.To = "
.CC = ""
.BCC = ""
.Subject = Me.Label1.Caption
.Body = Me.TextBox1.Text
.display 'or use .Display
End With

Set OutMail = Nothing
Set OutApp = Nothing
Unload Me
End Sub

I am not sure if I can use CDO.....I tried using it but didnt succeed
for some reason.


Have you try to use the commented blue code lines in the examples ??




--
Regards Ron de Bruin
http://www.rondebruin.nl



"Vikram" wrote in message ups.com...
Hi Ron

I have following code in the "submit" command button on my userform. It
sends the email, but I want to be able to have custom subject & body to
every email based on user input.

e.g. on my userform, Complaint Number (which is auto generated) is
shown on a label called "txtCompno" and Customer name is selected by
user from a combobox called "txtCustomer". Both these change with every
new complaint entry. I want every email to have both these specified in
the subject & body so that the recipients can go back to database and
search for that complaint number.

I am not sure if I can use CDO.....I tried using it but didnt succeed
for some reason.

Would appreciate your help.

Cheers

Vikram

================================================== ====
Dim aOutlook As Object
Dim aEmail As Object
Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String

Set aOutlook = CreateObject("Outlook.Application")
Set aEmail = aOutlook.CreateItem(0)
'set sheet to find address for e-mails as I have several people to mail
to
Set rngeAddresses = ActiveSheet.Range("B7:B7")
For Each rngeCell In rngeAddresses.Cells
strRecipients = strRecipients & ";" & rngeCell.Value
Next
'set Importance
aEmail.Importance = 2
'Set Subject
aEmail.Subject = "A new complaint no " & Me.txtcompno.Caption & " is
logged"
'Set Body for mail
aEmail.Body = "Please log onto the Customer Complaint System to check
Complaint no " & txtcompno.Caption & " for " & txtcustomer & " entered
today."
'Set Recipient
aEmail.To = strRecipients
aEmail.Send
================================================== ============