+ Reply to Thread
Results 1 to 3 of 3

Automatic emailing

Hybrid View

  1. #1
    Registered User
    Join Date
    06-30-2015
    Location
    New York
    MS-Off Ver
    2010
    Posts
    2

    Automatic emailing

    Hello,

    I am trying to get excel to email a sales rep when their client account is nearing expiration. I have been through all of the forums and help sites trying to figure this out and I keep getting the same error, "error 91: object variable not set yet," I definitely did set it. Additioanlly, the mnacro deosnt recognize when the value of the specified cell goes above the limit i set it at. my code is reproduced below. I would appreciate any and all help. This is my second day ever dealing with VBA so thank you in advacne for your patience in dealing with me. I have attached the excel file as well.

    regards,
    Jacob

    Option Explicit
    
    
    Private Sub Worksheet_Calculate()
        Dim FormulaRange As Range
        Dim NotSentMsg As String
        Dim MyMsg As String
        Dim SentMsg As String
        Dim MyLimit As Double
    
        NotSentMsg = "No"
        SentMsg = "Yes"
    
       
        MyLimit = 1
    
       
        Set FormulaRange = Me.Range("m4:m10")
    
        On Error GoTo EndMacro:
        For Each FormulaCell In FormulaRange.Cells
            With FormulaCell
                If IsNumeric(.Value) = False Then
                    MyMsg = "Not numeric"
                Else
                    If .Value > MyLimit Then
                        MyMsg = SentMsg
                        If .Offset(0, 1).Value = NotSentMsg Then
                            Call Mail_with_outlook2
                        End If
                    Else
                        MyMsg = NotSentMsg
                    End If
                End If
                Application.EnableEvents = False
                .Offset(0, 1).Value = MyMsg
                Application.EnableEvents = True
            End With
        Next FormulaCell
    
    ExitMacro:
        Exit Sub
    
    EndMacro:
        Application.EnableEvents = True
    
        MsgBox "Some Error occurred." _
             & vbLf & Err.Number _
             & vbLf & Err.Description
    
    End Sub
    And the email code is

    Option Explicit
    
    Public FormulaCell As Range
    
    
    Sub Mail_with_outlook2()
    
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strto As String, strcc As String, strbcc As String
        Dim strsub As String, strbody As String
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        strto = Cells(FormulaCell.Row, "P").Value
        strcc = ""
        strbcc = ""
        strsub = "Your subject"
        strbody = ""
    
        With OutMail
            .To = strto
            .CC = strcc
            .BCC = strbcc
            .Subject = strsub
            .Body = strbody
            .Display
        End With
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    Smart ledger 1.0.xlsm

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Automatic emailing

    I went through your code and found that it errors at
    strto = Cells(FormulaCell.Row, "P").Value
    Not sure why it errors there, I just now that it has something to do with the statement AFTER the =.
    I changed it to
    strto = "" 'Cells(FormulaCell.Row, "P").Value
    And the code ran with it removed
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    06-30-2015
    Location
    New York
    MS-Off Ver
    2010
    Posts
    2

    Re: Automatic emailing

    thank you. Works great now. 1 final question. How would I get the macro to run everytime I save the document?

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. need help figuring where to start with automatic emailing of worksheets
    By DFrank231 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2015, 05:18 PM
  2. Replies: 0
    Last Post: 04-27-2012, 07:32 AM
  3. Automatic emailing of protected worksheets, please help.
    By michellecairns in forum Excel General
    Replies: 0
    Last Post: 11-15-2011, 05:14 AM
  4. Automatic Update from a site and automatic ranking-Possible?
    By striker_rage in forum Excel General
    Replies: 3
    Last Post: 12-01-2008, 11:34 AM
  5. automatic emailing of records in a worksheet
    By Richard Flame in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-19-2007, 06:34 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