Hello
I a working on a program to email invoices to a distribution list for my team.
The program filters by the reps BillingCode then by if the group gets emails or online notifcatons. It then runs a loop based on a subcount on the workbook (in B2).
The filters are working correctly but when the loop run it acts as if it's unfiltered.
I a working on a program to email invoices to a distribution list for my team.
The program filters by the reps BillingCode then by if the group gets emails or online notifcatons. It then runs a loop based on a subcount on the workbook (in B2).
The filters are working correctly but when the loop run it acts as if it's unfiltered.
Code:
Option Explicit
Sub DraftOutlookEmails()
'*******************************************************************
'Microsoft Outlook XX.X Object Library is required to run this code
'*******************************************************************
Dim objOutlook As Outlook.Application
Dim Mail As Outlook.MailItem
Dim lCounter As Long
Set objOutlook = Outlook.Application
Rows("3:3").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Dim wsMLOG As Excel.Worksheet
Set wsMLOG = Sheets("Master Log")
Dim rngTable1 As Excel.Range
Set rngTable1 = wsMLOG.Range("A4").CurrentRegion
Dim rngLessHeader As Excel.Range, rngRows As Variant, rngRow1 As Long
Set rngLessHeader = gf_rngGet_TableData_Range(rngTable1)
Dim BACode As Variant
BACode = InputBox("Enter BA Code")
rngTable1.AutoFilter Field:=5, Criteria1:=BACode
rngTable1.AutoFilter Field:=7, Criteria1:="E-mail"
Set rngTable1 = wsMLOG.Range("A4").CurrentRegion
Set rngLessHeader = gf_rngGet_TableData_Range(rngTable1)
rngRows = wsMLOG.Range("B2")
rngRow1 = rngLessHeader.Rows(1).Count
Dim i As Long
Do Until i = rngRows
Set Mail = objOutlook.CreateItem(olMailItem)
Mail.To = wsMLOG.Range("L" & i + 5).Value & ";" & wsMLOG.Range("M" & i + 5).Value & ";" & wsMLOG.Range("N" & i + 5).Value & ";" & wsMLOG.Range("O" & i + 5).Value & ";" & wsMLOG.Range("P" & i + 5).Value & ";" & wsMLOG.Range("Q" & i + 5).Value & ";" & wsMLOG.Range("R" & i + 5).Value & ";" & wsMLOG.Range("S" & i + 5).Value
Mail.Subject = "Hello There"
Mail.Body = "Hello There"
Mail.Close (olSave)
Set Mail = Nothing
i = i + 1
Loop
End Sub