So I used this excellent article How to automatically send email based on cell value in Excel? (extendoffice.com) and scrapped together answers from the replies to get this working as I need it to but the last piece I can't figure out is how to duplicate what I've done to run for multiple cells. I've tried to copy/paste and rearrange the code with different values like C4, C5, etc. but I always get errors. I have it working great to where if the value in C3 is < 5 it will send an email when the workbook is saved.What I need now, since this is for an inventory sheet, is to have multiple other cell values checked at different values. For example, if only C3 < 5 send an email. If only C4 is < 6 send an email. If C3 < 5, C4 is < 6 and C5 < 3 send an email. It would be nice if only one email is generated on save with all of the values that matched the < criteria.In real-world terms (not coding terms), the spreadsheet is a place for technicians to check in and out items from storage. What I am trying to do is have an email automatically sent when someone saves the workbook and the inventory level of an item has dropped below a specific value so I know that an order needs to be placed soon. So far this is my code:
ThisWorkbook
Приватна підпорядкована книга_AfterSave(ByVal Success As Boolean)
On Error Resume Next
Dim xI як ціле число
Dim xRg As Range
Set xRg = Range("Information!C3")
xI = Int(xRg.Value)
If xI < 5 Then
Телефонуйте Mail_small_Text_Outlook
End If
End Sub
Модуль1
Sub Mail_small_Text_Outlook()
Зменшіть xOutApp як об’єкт
Змінити xOutMail як об’єкт
Заглушити xMailBody як рядок
Встановіть xOutApp = CreateObject("Outlook.Application")
Встановити xOutMail = xOutApp.CreateItem(0)
xMailBody = "Привіт" & vbNewLine & vbNewLine & _
"Це рядок 1" & vbNewLine & _
Range("Information!C3") & vbNewLine & _
«Це рядок 2»
On Error Resume Next
За допомогою xOutMail
.To = "Адреса електронної пошти"
.CC = ""
.BCC = ""
.Subject = "відправити тестом значення комірки"
.Body = xMailBody
.Відобразити або використовувати .Send
Кінець з
При помилці GoTo 0
Встановіть xOutMail = Нічого
Встановіть xOutApp = Нічого
End Sub
ThisWorkbook
Приватна підпорядкована книга_AfterSave(ByVal Success As Boolean)
On Error Resume Next
Dim xI як ціле число
Dim xRg As Range
Set xRg = Range("Information!C3")
xI = Int(xRg.Value)
If xI < 5 Then
Телефонуйте Mail_small_Text_Outlook
End If
End Sub
Модуль1
Sub Mail_small_Text_Outlook()
Зменшіть xOutApp як об’єкт
Змінити xOutMail як об’єкт
Заглушити xMailBody як рядок
Встановіть xOutApp = CreateObject("Outlook.Application")
Встановити xOutMail = xOutApp.CreateItem(0)
xMailBody = "Привіт" & vbNewLine & vbNewLine & _
"Це рядок 1" & vbNewLine & _
Range("Information!C3") & vbNewLine & _
«Це рядок 2»
On Error Resume Next
За допомогою xOutMail
.To = "Адреса електронної пошти"
.CC = ""
.BCC = ""
.Subject = "відправити тестом значення комірки"
.Body = xMailBody
.Відобразити або використовувати .Send
Кінець з
При помилці GoTo 0
Встановіть xOutMail = Нічого
Встановіть xOutApp = Нічого
End Sub