User form Email with outlook

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
781
Office Version
  1. 365
I have this table and I found the code below this table on the net how can i modify it so when select a company picks the mailto, cc, bcc, subject and body message address to each company.

Here it's the table

CompanySubjectMsg BodyContactsEmailCCBccMsg Formula
5LinxPast due Invoice(s)# 5LinxSEND TO MONIQUE FIRSTPast due Invoice(s)#
Alive WorldwidePast due Invoice(s)# Alive WorldwideDear Susann,%0AThis is a friendly reminder that your account has a past due balance of Thank you for your attention to this matter.Susann Paulsonsusann@revvnrg.comPast due Invoice(s)#
AmkeyPast due Invoice(s)# AmkeyDearMo,%0AThis is a friendly reminder that your account has a past due balance of $, Invoices #. Thank you for your prompt attention to this matter.Moyvonnemo@gmail.comLinking textPast due Invoice(s)#
ASEAPast due Invoice(s)# ASEADear,%0AThis is a friendly reminder that your account has a past due balance of $, Invoices #. Thank you for your prompt attention to this matter.accountspayable@asea.net accountspayable@asea.netmbarszcz@hyperwallet.comPast due Invoice(s)#
AvisaePast due Invoice(s)# AvisaeDear Brooks,%0AThis is a friendly reminder that your account has a past due balance of $, Invoices #. Thank you for your prompt attention to this matter.Brooks Yatesbrooks@avisae.comPast due Invoice(s)#

<tbody>
</tbody>

here it's the code:

Code:
Option Explicit

Private Sub Cbn_Send_Click()
  Dim OutObj As Object  ' Late binding
  Dim Email As Object
  Dim Msg As String
  Dim Ctrl As Control
  Dim sReceiver As String
  ' Find mail adress
  sReceiver = Worksheets("Param").Range("E:E").Find(What:=Me.ComboBox1.Value).Offset(0, 1).Value
  ' Create OUTLOOK instance
  Set OutObj = CreateObject("Outlook.Application")
  ' Create container object for mail
  Set Email = OutObj.CreateItem(0)
  ' Create email : Object, corp post, receiver
  Email.Subject = "Invoice(s) #"
  ' Initialize message
  Msg = ""
  ' For each control in USF
  For Each Ctrl In Me.Controls
    ' IF it's TextBox or Combobox
    If TypeOf Ctrl Is MSForms.TextBox Or TypeOf Ctrl Is MSForms.ComboBox Then
      ' Add value in message
      Msg = Msg & Ctrl.Text & vbCrLf
    End If
  Next Ctrl
  ' Register message in body
  Email.Body = Msg
  ' Possible to add attachment
  'Email.Attachments.Add sPath & sFic
  '
  Email.To = sReceiver
  ' Send mail directly
  'Email.Send
  ' Or see mail
  Email.Display
  ' Clean object
  Set Email = Nothing
  Set OutObj = Nothing
End Sub


Private Sub UserForm_Initialize()
  Dim Lig As Long
  Me.ComboBox1.Clear
  With Worksheets("Param")
    For Lig = 2 To 10
      If .Range("A" & Lig) <> "" Then
        Me.ComboBox1.AddItem .Range("A" & Lig).Value
      End If
    Next Lig
  End With
End Sub

thanks
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,215,651
Messages
6,126,023
Members
449,281
Latest member
redwine77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top