By kylejohnson95757@gmail.com Dé hAoine, 01 Márta 2019
Posted in Excel
Freagraí 0
Is maith 0
tuairimí 3.2K
Vótaí 0
Haigh,
I'm new to VBA. I wrote a code to send an email if there is a cell value change in column F, and the code works great. But I want to make sure the workbook is saved prior to sending out the email. The email text body must include the reference cell value, which is the value from column A of value changed row. Please do not use msg, it will not work with the workbook. The workbook has a form and it will load the input value to the designated cells. The code works fine with the form. But if someone goes into the sheet and manually update the value, the email will send out to users, which I don't want until the file is saved. Please help! Thanks in advance.

Fo-Bileog Oibre Príobháideach_Change (Sprioc ByVal Mar Raon)
Dim s1, s2, s3, s4, s5, s6 As Range
Set s1 = Range("F1310:F1334")
Set s2 = Range("F1426:F1450")
Set s3 = Range("F1339:F1363")
Set s4 = Range("F1455:F1479")
Set s5 = Range("F1368:F1392")
Set s6 = Range("F1397:F1421")
Ar Lean Earráid Aghaidh
Má tá Target.Cells.Count > 1 Ansin Scoir Fo
'find value changed in column F
If Intersect(Target, Union(s1, s2, s3, s4, s5, s6)) Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value <> "" Then
Dim xOutApp Mar Réad
Dim xOutMail Mar Réad
Dim xMailBody Mar Teaghrán
Dim xMailText As String
Socraigh xOutApp = CreateObject ("Outlook.Application")
Socraigh xOutMail = xOutApp.CreateItem(0)
'index value from column A of the row that value changed to included in mail body
xMailText = Target.Offset(, -5).Value
xMailBody = "Dia duit ansin" & vbNewLine & vbNewLine &_
"Invoice Received for " & xMailText & vbNewLine & vbNewLine & _
"Thanks" & vbNewLine & vbNewLine & _
"Mr. J"
Ar Lean Earráid Aghaidh
Le xOutMail
.To = "test@gmail.com"
.CC = ""
.BCC = ""
.Subject = "Invoice Received"
.Comhlacht = xMailBody
.Seol
Deireadh Le
Ar Earráid TéighTo 0
Socraigh xOutMail = faic
Socraigh xOutApp = faic
Deireadh Má
Fo Deireadh
Féach ar an bPost Iomlán