Automatic Email VBA help needed

Golfpro1286

New Member
Joined
Aug 22, 2018
Messages
30
I hope this is as easy as it sounds, but I could not figure it out. I am using the following template to automatically generate an outlook email, which seems to be working, what I can't figure out is how to properly reference certain cells in the code. I was hoping to have the mail to address be selected from cell H3 in sheet named "Setup Sheet" and in the subject have it say "25% Inspection due for (Cell H1 in "Setup Sheet).

Dim xRg As Range
'Update by Extendoffice 2018/3/7
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Range("C11"), Target)
If xRg Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value > 0.24 Then
Call Mail_small_Text_Outlook
End If
End Sub
Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
"This email is to let you know that an inspection is due for" & vbNewLine & _
"This is line 2"
On Error Resume Next
With xOutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "25% Inspection Due for ... "
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub

Thanks for any help!
 
Last edited:
Ok, I'm assuming Sheet3 was the correct sheet for this action to fire !
Is the macro actually firing ?
Put a bookmark in the On error row ( that's a click in the column next to the on error text, so it turns brown.
Change something in the worksheet, and that row should turn yellow....if not I'd say you are either using the wrong sheet module OR you have enablevents turned off !!
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I did this and the line turned yellow. I was not sure how to turn on the enablevents, so I did a quick google search and found this string of code:

Code:
Sub Appl_EnableEvents()    Application.EnableEvents = True
End Sub

I tried adding it in the sheet module a few different ways, but nothing worked. Is this the right code to have in there? And if so, where should it go?
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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