• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Save, send email if value of cell is..

varreddor

New Member
Hello everyone,

My skills in VBA are low.
With some research on the web I've reached this:

>>> use code - tags <<<

Code:
Dim xRg As Range

Private Sub contagem(ByVal Target As Range)

    On Error Resume Next
    If Target.Cells.Count > 1 Then Exit Sub
  Set xRg = Intersect(Range("D22"), Target)
    If xRg Is Nothing Then Exit Sub
    If IsNumeric(Target.Value) And Target.Value > 45000 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 = "Olá Luisa," & vbNewLine & vbNewLine & _
              "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" & vbNewLine & _
              "xxxxxxxxxxxxxxxxxxxx" & vbNewLine & vbNewLine & _
              "xxxxxxxxxxxxxxxx"
    On Error Resume Next
    With xOutMail
        .To = "xxxxxxxxx"
        .CC = "xxxxxxxxxxx;" & "xxxxxxxxxxxxx"
        .BCC = ""
        .Subject = "xxxxxxxxxxxxxxxxxxxx"
        .Body = xMailBody
        .Display   'or use .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing

End Sub

The macro works if I manually change the value in the cell.
I want the macro to run when someone (a colleague from work) saves the file. So I placed this in workbook module:


Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

    Call Sheet13.contagem
    
End Sub

Well, of course, it does not work o_O
Ive searched for a solution here in the forum but without success.
Just some details: the colleague add values in cells from different sheets almost everyday. I have another sheet to make some math with those values, where is the first code and D22 cell. All in same workbook.

Can someone help? I feel I am close :confused:
 
Last edited by a moderator:
Hey.
In attachment a sample file.
Contagem only to check value at cell D22 in sheet 13 "Contador".
 

Attachments

  • varreddor_testing_v2.xlsm
    106.1 KB · Views: 4
varreddor
... only checking empty
... ... cell which should write in code ( check this file )
... ... ... but because empty - then no email ( Ps ... I don't use Outlook ... I cannot verify this over 50% )
 

Attachments

  • varreddor_testing_v2.xlsm
    103.5 KB · Views: 4
Back
Top