Results 1 to 8 of 8

HELP! Need help with macro that automatically sends email when...

Threaded View

KngCharming HELP! Need help with macro... 08-27-2013, 09:08 AM
Solus Rankin Re: HELP! Need help with... 08-27-2013, 09:50 AM
KngCharming Re: HELP! Need help with... 08-27-2013, 12:37 PM
Solus Rankin Re: HELP! Need help with... 08-27-2013, 01:10 PM
KngCharming Re: HELP! Need help with... 08-28-2013, 08:07 AM
Solus Rankin Re: HELP! Need help with... 08-28-2013, 08:27 AM
KngCharming Re: HELP! Need help with... 08-28-2013, 10:23 AM
Solus Rankin Re: HELP! Need help with... 08-28-2013, 01:01 PM
  1. #1
    Registered User
    Join Date
    08-27-2013
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    4

    HELP! Need help with macro that automatically sends email when...

    Hi,

    I am putting together a database that will track inventory. I am trying to make a set of macros that will allow my excel workbook to automatically send an email whenever any cell in a specific column (actualy inventory) is less than the respective cell in the column adjacent to it (minimum stock). I copied most of this from examples online. Now the email sending macro works fine, I need help with the trigger macro to automatically send the email when the correct conditions are met (a cell in column C has a value less than a column on the same row in D, eg. c3<d3) So far I am losing sleep and getting nowhere... Please help! Here is what I have so far:

    Private Sub Workbook_SheetCalculate()
        Dim FormulaRange As Range
        Dim NotSentMsg As String
        Dim MyMsg As String
        Dim SentMsg As String
        Dim MyLimit As Range
        Dim Formulacell2 As Integer
    
        NotSentMsg = "Not Sent"
        SentMsg = "Sent"
    
        'Above the MyLimit value it will run the macro
        Set MyLimit = ActiveWorkbook.Ranges("D2:D2000")
    
        'Set the range with Formulas that you want to check
        Set FormulaRange = ActiveWorkbook.Ranges("C2:C1000")
        
        On Error GoTo EndMacro:
        
        For Each Formulacell In MyLimit.Cells
            With Formulacell
                If IsNumeric(.Value) = False Then
                    MyMsg = "Not Numeric"
                Else
                    Formulacell2 = Formulacell.Value
                  
                    
                For Each Formulacell In FormulaRange.Cells
                    With Formulacell
                        If IsNumeric(.Value) = False Then
                                MyMsg = "Not Numeric"
                        Else
                            If .Value > Formulacell2 Then
                                    MyMsg = SentMsg
                                If .Offset(0, 1).Value = NotSentMsg Then
                                    Call Mail_small_Text_Outlook
                                End If
                        Else
                                MyMsg = NotSentMsg
                            End If
                        End If
                Application.EnableEvents = False
                .Offset(0, 1).Value = MyMsg
                Application.EnableEvents = True
                    
                    End With
                Next Formulacell
            
            End With
        Next Forumlacell
            
    ExitMacro:
        Exit Sub
    
    EndMacro:
        Application.EnableEvents = True
    
        MsgBox "Some Error occurred." _
             & vbLf & Err.Number _
             & vbLf & Err.Description
    
    End Sub
    Sub Mail_small_Text_Outlook()
    'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
    'Working in Excel 2000-2013
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String
        Dim rick As String
        Dim orrett As String
        Dim rng As Range
    
      Set rng = Nothing
        On Error Resume Next
        'Only the visible cells in the selection
        Set rng = Selection.SpecialCells(xlCellTypeVisible)
        'You can also use a fixed range if you want
        'Set rng = Sheets("YourSheet").Range("D4:D12").SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
    
        If rng Is Nothing Then
            MsgBox "The selection is not a range or the sheet is protected" & _
                   vbNewLine & "please correct and try again.", vbOKOnly
            Exit Sub
        End If
    
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
    
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        
        rick = "rick.@companyname.com"
        
        orrett = "orrett@companyname.com"
        
        strbody = "Hi there" & vbNewLine & vbNewLine & _
                  "Cell A1 is changed" & vbNewLine & _
                  "This is line 2" & vbNewLine & _
                  "This is line 3" & vbNewLine & _
                  "This is line 4"
    
        On Error Resume Next
        With OutMail
            .To = orrett
            .CC = ""
            .BCC = ""
            .Subject = "Low Inventory Warning"
            .Body = strbody
            'You can add a file like this
            '.Attachments.Add ("C:\test.txt")
            .Display
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    F
    Last edited by arlu1201; 08-27-2013 at 09:15 AM. Reason: Use code tags in future.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Email loop only sends first email from outlook.
    By vamosj in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-16-2013, 04:33 PM
  2. VBS/OutMail script and macro sends email message twice
    By Andrew_Harris in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-17-2013, 08:57 PM
  3. Replies: 4
    Last Post: 11-20-2012, 06:39 AM
  4. Macro that sends email automatically once a week?
    By GTfan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2012, 02:44 PM
  5. A macro that looks up a email from sheet2 and sends email
    By AdderLee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-10-2012, 02:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1