Results 1 to 3 of 3

Automatic mail on due date (30 days or closer)

Threaded View

  1. #1
    Registered User
    Join Date
    09-14-2012
    Location
    Malta
    MS-Off Ver
    Excel 2003
    Posts
    2

    Automatic mail on due date (30 days or closer)

    I am trying to do a vba script so that i run excel using microsoft scheduler and if it finds something which is due in 30 days it will auto0matically send a mail. now for the first column its working fine but for the second it stops. can anyone help me please


    Sub Workbook_Open()
     
    Dim lngLast As Long
    Dim lngCounter As Long
    
    Application.ScreenUpdating = False
    lngLast = Cells(Rows.Count, "AB").End(xlUp).Row
    For lngCounter = 2 To lngLast
      With Cells(lngCounter, "AB")
     If DateDiff("d", Date, .Value) <= 30 Then
            *** = "A" & .Row
          ass2 = "B" & .Row
          ass3 = "AB" & .Row
        firstdate = Range(ass3).Value
    msg = DateDiff("d", Date, firstdate)
     Set objEmail = CreateObject("CDO.Message")
            
            With objEmail
                With .Configuration.Fields
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
                        = "smtp.go.net.mt"
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") _
                        = "30"
                    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") _
                        = "2"
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
                        = "25"
                    .Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") _
                        = "instrumentation@aurobindomalta.com"
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") _
                        = "0"
                    .Update
                End With
                .To = "medio@onvol.net"
                .From = "instrumentation@aurobindomalta.com"
                .Subject = "Calibration due for" & Space(2) & Range(***).Value
                .TextBody = Range(ass2).Value & "(" & Range(***).Value & ")" & Space(2) & "has its calibration  due in" & Space(2) & msg & Space(2) & "days. Kindly contact personell in charge."
              
                .send
            End With
            Set objEmail = Nothing
    End If
    End With
    Next lngCounter
    Application.ScreenUpdating = True
    cal
    End Sub
    
    Sub cal()
    
    
    Dim lngLast As Long
    Dim lngCounter As Long
    
    Application.ScreenUpdating = False
    lngLast = Cells(Rows.Count, "AC").End(xlUp).Row
    For lngCounter = 2 To lngLast
      With Cells(lngCounter, "AC")
     If DateDiff("d", Date, .Value) <= 30 Then
          *** = "A" & .Row
          ass2 = "B" & .Row
          ass3 = "AC" & .Row
        firstdate = Range(ass3).Value
    msg = DateDiff("d", Date, firstdate)
           Set objEmail = CreateObject("CDO.Message")
            
            With objEmail
                With .Configuration.Fields
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
                        = "smtp.go.net.mt"
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") _
                        = "30"
                    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") _
                        = "2"
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
                        = "25"
                    .Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") _
                        = "instrumentation@aurobindomalta.com"
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") _
                        = "0"
                    .Update
                End With
              
                .To = "medio@onvol.net"
                .From = "instrumentation@aurobindomalta.com"
                .Subject = "Calibration due for" & Space(2) & Range(***).Value
                .TextBody = Range(ass2).Value & "(" & Range(***).Value & ")" & Space(2) & "has its calibration due in" & Space(2) & msg & Space(2) & "days. Kindly contact personell in charge."
              
                .send
            End With
            Set objEmail = Nothing
        End If
      End With
    Next lngCounter
    Application.ScreenUpdating = True
    
    pm
    
    End Sub
    
    Sub pm()
    
    
    Dim lngLast As Long
    Dim lngCounter As Long
    
    Application.ScreenUpdating = False
    lngLast = Cells(Rows.Count, "AD").End(xlUp).Row
    For lngCounter = 2 To lngLast
      With Cells(lngCounter, "AD")
    If DateDiff("d", Date, .Value) <= 30 Then
          *** = "A" & .Row
          ass2 = "B" & .Row
          ass3 = "AD" & .Row
        firstdate = Range(ass3).Value
    msg = DateDiff("d", Date, firstdate)
           Set objEmail = CreateObject("CDO.Message")
            
            With objEmail
                With .Configuration.Fields
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
                        = "smtp.go.net.mt"
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") _
                        = "30"
                    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") _
                        = "2"
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
                        = "25"
                    .Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") _
                        = "instrumentation@aurobindomalta.com"
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") _
                        = "0"
                    .Update
                End With
                .To = "medio@onvol.net"
                .From = "instrumentation@aurobindomalta.com"
                .Subject = "Performance monitoring due for" & Space(2) & Range(***).Value
                .TextBody = Range(ass2).Value & "(" & Range(***).Value & ")" & Space(2) & "has its performance monitoring  due in" & Space(2) & msg & Space(2) & "days. Kindly contact personell in charge."
              
                .send
            End With
            Set objEmail = Nothing
        End If
      End With
    Next lngCounter
    Application.ScreenUpdating = True
    
    End Sub
    Instrumentation Logsheet - Copy.zip
    Last edited by medioman; 09-15-2012 at 07:08 AM.

Thread Information

Users Browsing this Thread

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

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