Taha Jawadi
New Member
- Joined
- Feb 24, 2021
- Messages
- 1
- Office Version
- 365
- 2016
- Platform
- Windows
Dears,
I will be thankful if someone helps me in this .
I want a macro that checks a specific cell value :
For example:
If the cell value is > 70 then
1- Takes a capture of a certain cells range
2- add to outlook email body
3-An email will be sent to the recipient
I have to block of codes and i dont know how to mix them in order to get what i need
First code: Takes a picture of certain cells range
sub Send_Email_To_Agent()VBA Code:
On Error GoTo ende
Dim outlook As Object
Dim newEmail As Object
Dim xInspect As Object
Dim pageEditor As Object
Set outlook = CreateObject("Outlook.Application")
Set newEmail = outlook.CreateItem(0)
With newEmail
.To = Sheet12.Range("D32").Text
.CC = Sheet12.Range("E33").Text
.BCC = Sheet12.Range("E44").Text
.Subject = "HOLD Performance " & " Date Of Observation : " & Date
.Body = Sheet12.Range("D34").Text & vbNewLine & Sheet12.Range("D35").Text & vbNewLine & Sheet12.Range("D36").Text & vbNewLine & Sheet12.Range("D37").Text
.display
Set xInspect = newEmail.GetInspector
Set pageEditor = xInspect.WordEditor
Sheet12.Range("A30:B40").Copy
pageEditor.Application.Selection.Start = Len(.Body)
pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)
.display
.Send
Set pageEditor = Nothing
Set xInspect = Nothing
End With
Set newEmail = Nothing
Set outlook = Nothing
ende:
End Sub
2 Second code: Loops around emails and send
VBA Code:
Code:
Sub Button1_Click()
Dim olApp As Object
Dim olMailItm As Object
Dim iCounter As Integer
Dim Dest As Variant
Dim SDest As String
' Subject
strSubj = "Your HOLD Score " & TODAY - 1
On Error GoTo dbg
' Create a new Outlook object
Set olApp = CreateObject("Outlook.Application")
For iCounter = 1 To WorksheetFunction.CountA(Columns(1))
' Create a new item (email) in Outlook
Set olMailItm = olApp.CreateItem(0)
strBody = ""
useremail = Cells(iCounter, 1).Value
FullUsername = Cells(iCounter, 2).Value
Status = Cells(iCounter, 4).Value
HOLD = Cells(iCounter, 3).Value
'Make the body of an email
strBody = "Dear " & FullUsername & vbCrLf
strBody = strBody & " Your account in woshub.com domain is in" & HOLD & " state" & vbCrLf
strBody = strBody & "The date and time of the last password change is" & HOLD & vbCrLf
olMailItm.To = useremail
olMailItm.Subject = strSubj
olMailItm.BodyFormat = 1
' 1 – text format of an email, 2 - HTML format
olMailItm.Body = strBody
olMailItm.Send
Set olMailItm = Nothing
Next iCounter
Set olApp = Nothing
dbg:
'Display errors, if any
If Err.Description <> "" Then MsgBox Err.Description
End Sub
The idea is in a nutshell:
====> A macro that checks the cell if it is >70
====> sends an email with a screen shot of a certain cells range
Thank you alot for any possible help