Swapping email accounts on send

wmtsub

Active Member
Joined
Jun 20, 2018
Messages
322
Below is a snippet of the code I use to send emails from excel. I would like to expand this to change the sent from based on a list of vendors. So What I think is as the email is generating it would compare the field "VND" which is the vendors name against an excel spreadsheet and change the "BEHALF" to the corresponding email for the assigned account rep.

Do you think this can be done?


Code:
     Const Behalf = "wmtsubcontractors@cfm-us.com" ' <-- Name to send on behalf of  Exchange profile/account
    'Specify email recipients, subject, etc:
    .To = sal
    '.Cc = "carboncopy@..."
    .Subject = "- Past Due open Order Report for -   " & VND & "  ---  " & tdd
    .SentOnBehalfOfName = Behalf
    .Send '<-- Directly send out this email, use .Display instead for the debugging only
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Tyr this

Code:
     'Const Behalf = "wmtsubcontractors@cfm-us.com" ' <-- Name to send on behalf of  Exchange profile/account
     Set h = Sheets("Vendors")  'sheet name with vendors
     Set b = h.Columns("A").Find(VND, lookat:=xlWhole, LookIn:=xlValues)
     If Not b Is Nothing Then
        Behalf = h.Cells(b.Row, "B").Value
     Else
        Behalf = "wmtsubcontractors@cfm-us.com"
     End If
    'Specify email recipients, subject, etc:
    .To = sal
    '.Cc = "carboncopy@..."
    .Subject = "- Past Due open Order Report for -   " & VND & "  ---  " & tdd
    .SentOnBehalfOfName = Behalf
    .Send '<-- Directly send out this email, use .Display instead for the debugging only
 
Upvote 0
Thanks for the quick response. I cannot ge ti to work. I think it is becuase the vendor sheet is interfering with the workbook. I would actually prefer it to be a stand alone workbook. Can we do that?
 
Upvote 0
Test:

Code:
   'Const Behalf = "wmtsubcontractors@cfm-us.com" ' <-- Name to send on behalf of  Exchange profile/account
     set l = workbooks("book vendors.xlsx")   'open book name with vendors
     Set h = l.Sheets("Vendors")  'sheet name with vendors
     Set b = h.Columns("A").Find(VND, lookat:=xlWhole, LookIn:=xlValues)
     If Not b Is Nothing Then
        Behalf = h.Cells(b.Row, "B").Value
     Else
        Behalf = "wmtsubcontractors@cfm-us.com"
     End If
    'Specify email recipients, subject, etc:
    .To = sal
    '.Cc = "carboncopy@..."
    .Subject = "- Past Due open Order Report for -   " & VND & "  ---  " & tdd
    .SentOnBehalfOfName = Behalf
    .Send '<-- Directly send out this email, use .Display instead for the debugging only
 
Upvote 0
Thank you for the help. Just getting back to this now. The message boxes return the correct info but I can not seem to get the email to send on be half correctly. I did have to modify the code a bit to work so here is what I am using:


Code:
 Set l = Workbooks.Open("\\JAX2-FILE-01\Procurement\..  M A N A G E D  C O N T R A C T S\EDS\Account Representitive.xlsm")   'open book name with vendors
     Set h = Sheets("VENDORS")  'sheet name with vendors
     Set b = Columns("a").Find(vnd, lookat:=xlWhole, LookIn:=xlValues)
      
      
      If Not b Is Nothing Then
      Behalf = Cells(b.Row, "B").Value
      Else
      Behalf = "wmtsubcontractors@cfm-us.com"
      End If
MsgBox vnd
MsgBox b
MsgBox Behalf
   
    
    'Specify email recipients, subject, etc:
    .To = sal
    '.Cc = "carboncopy@..."
    .Subject = "- Past Due open Order Report for -   " & vnd & "  ---  " & tdd
    .SentOnBehalfOfName = Behalf
    
  '  .send '<-- Directly send out this email, use .Display instead for the debugging only
    .display
   
  End With
 
Upvote 0

Forum statistics

Threads
1,223,718
Messages
6,174,077
Members
452,542
Latest member
Bricklin

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