Sending Different Emails from Excel

MJN1965

New Member
Joined
Aug 5, 2020
Messages
7
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi all,
I have set up an if formula that ends with sending an automatice email. this is working 100% fine.

I want to send a different email based on a another set of rules but I keep getting a Syntax error.

My original VBA is :-
Sub MailOutlook16()
'By Martin Nesbitt @ MJNSystems
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Village/Sceme - " & [$c10] & vbNewLine & vbNewLine & "Work Request " & [$D16] & vbNewLine & vbNewLine & GetUserName & " has requested a new PO value above the value of £1000" & vbNewLine & vbNewLine & _
"Requested new value - £" & [$ae16] & vbNewLine & vbNewLine & "Please evaluate this request and either Authorise or Reject as appropriate"
On Error Resume Next
With xOutMail
.To = "Kevin.tanner@extracare.org.uk"
.CC = [c9]
.BCC = ""
.Subject = "SCM - Purchase Order Increase Request"
.Body = xMailBody
.display 'use .Send or .display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub

I want to be able to also send out :-
Sub MailOrder16()
'By Martin Nesbitt @ MJNSystems
Dim OutApp As Object
Dim OutMail As Object
Dim MailBody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
MailBody = "Village/Sceme - " & [$c10] & vbNewLine & vbNewLine & "Work Request " & [$D16] & vbNewLine & vbNewLine & _
GetUserName & " has requested you attend " & [c16] & vbNewLine & vbNewLine & "UPRN I.D. - " & [B16] & vbNewLine & vbNewLine & _
" The triaged repair description is - " & [AC16] & vbNewLine & vbNewLine & "The Job Priority has been set as " & [t16] & " which is " & [bn16] & " response" & vbNewLine & vbNewLine & _
"Your Initial Po Value has been set at - £" & [$ad16] & vbNewLine & vbNewLine & _
"Please confirm receipt of this Require with Engineer ETA to Inbox repairrequest@extracare.org.uk"
On Error Resume Next
With OutMail
.To = [Bq16]
.CC = "repairrequest@extracare.org.uk"
.BCC = ""
.Subject = "Request to attend Repair Request"
.Body = MailBody
.display 'use .Send or .display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

I get the message

The Syntax of this name isn't correct.

Verify that the name:
-Starts with a letter or Underscore(_)
_Doesn't include a space or character that isnt allowed
_Doesn't conflict with an existing name in the workbook.

I have used the formula =if(M16<>"Select Contactor",MailOrder16(),"")

can anybody offer help

Thanks
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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