Schanemans
New Member
- Joined
- May 11, 2021
- Messages
- 1
- Office Version
- 2013
- Platform
- Windows
Hello, I have been trying to do a VBA code that will send a different email for certain workbook sheets. For example I have 6 sheets and when I open the workbook I want it to send the email for each tab automatically based on cell data. The body of the emails are all different. I am having trouble finding a code for this. Can some please help? I have included a sample of my spreadsheet. I have the code currently in ThisWorkbook. I have tried it in the sheets individually, a call code, loop but I need it to have the different emails that are specific to the corresponding sheets-See VBA code at bottom (the email body is different on each one). I only need 4 of the sheets to send emails. It won't send any emails. But does if I just do 1 code on 1 sheet only.
Pasted copy of workbook:
Mini Sheets in order:
1-
2-
3-
4-
5-
6-
Set OutMail = Nothing
Set OutApp = Nothing
End Sub[/CODE]
Pasted copy of workbook:
Mini Sheets in order:
1-
Test Test2.xlsm | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | F | G | M | N | O | P | Q | R | |||||||||
5 | Status | Agency/Owner/Link | Type | Agreement Title/Project Name | Begin Date | Term/Exp | Staff Contact First Name | Staff Contact Last Name | Staff Email | Reminder Sent | Was Reminder Sent | Date To Send Reminder | ||||||||
6 | Active | Puget Sound Council of Governments | Interlocal Agreement | Interlocal Cooperation Act of 1967 | 5/12/1977 | On Going | Too | Old | oldt@cobl.us | |||||||||||
7 | Inactive | Erickson Short Plat | Agreement | Water & Sewer Developer Agreement for Erickson Short Plat 194th & 75 SE SP#96-7 | 8/28/1998 | 4/11/2021 | Too | Old | oldt@cobl.us | 3/12/2021 | ||||||||||
Agreements ACTIVE |
Cell Formulas | ||
---|---|---|
Range | Formula | |
A6:A7 | A6 | =IF(G6<$H$1,"Inactive",("Active")) |
O6:O7 | O6 | =IF((OR(M6="",N6="")),"",HYPERLINK(LOWER(N6&LEFT(M6,1))&"@cobl.us")) |
R6:R7 | R6 | =IF((OR(G6="Unknown",G6="On Going",G6="Auto-Renewing",G6="Until Annexed",G6="Until Complete",G6="Upon Completion",G6="",G6="Life of property",G6="Annually")),"",G6-$I$1) |
2-
Test Test2.xlsm | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | F | G | M | N | O | P | Q | R | |||||||||
5 | Status | Agency/Owner/Link | Type | Agreement Title/Project Name | Begin Date | Term/Exp | Staff Contact First Name | Staff Contact Last Name | Staff Email | Reminder Sent | Was Reminder Sent | Date To Send Reminder | ||||||||
6 | Active | Astound Broadband | Franchise Agreement | Telecommunications Franchise for Broadband internet (wave) - Ord 1540 | 3/15/2016 | 3/15/2031 | Too | Old | oldt@cobl.us | 2/13/2031 | ||||||||||
7 | Inactive | Astound Broadband | Franchise Agreement | Telecommunications Franchise for Broadband internet (wave) - Ord 1540 | 3/15/2016 | 4/11/2021 | Too | Old | oldt@cobl.us | 3/12/2021 | ||||||||||
Franchise Agreements ACTIVE |
Cell Formulas | ||
---|---|---|
Range | Formula | |
A6:A7 | A6 | =IF(G6<$H$1,"Inactive",("Active")) |
O6:O7 | O6 | =IF((OR(M6="",N6="")),"",HYPERLINK(LOWER(N6&LEFT(M6,1))&"@cobl.us")) |
R6:R7 | R6 | =IF((OR(G6="Unknown",G6="On Going",G6="Auto-Renewing",G6="Until Annexed",G6="Until Complete",G6="Upon Completion",G6="",G6="Life of property",G6="Annually")),"",G6-$I$1) |
3-
Test Test2.xlsm | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | F | G | |||||||||
5 | Status | Agency/Owner | Type | Agreement Title/Project Name | Begin Date | Term/Exp | ||||||||
6 | Inactive | Fank Coluccio Construction Co. | Agreement | Lake Tapps Sewerage Project Ineterceptors Phase I (Contract S79-1) - Schedule A | 8/27/1979 | 6/3/1905 | ||||||||
7 | Inactive | Tucci & Sons, Inc. | Agreement | Lake Tapps Sewerage Project Ineterceptors Phase I (Contract S79-1) - Schedule B & C | 8/27/1979 | 6/3/1905 | ||||||||
Agreements INACTIVE |
Cell Formulas | ||
---|---|---|
Range | Formula | |
A6:A7 | A6 | =IF(G6<$H$1,"Inactive",("Active")) |
4-
Test Test2.xlsm | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | F | J | K | L | Q | R | S | T | U | V | |||||||||||
5 | Status | Contractor/Owner/Principal | Project Name/Title | Project Type | Bond Type | Start Date | Expire Date | Release Date | Staff Contact First Name | Staff Contact Last Name | Staff Email | Reminder Sent | Was Reminder Sent | Date To Send Reminder | ||||||||||
6 | Active | Cascade RCL, LLC | Stream Mitigation Planting | Developer | Assignment of Funds | 12/18/2018 | Until Released | Too | Old | oldt@cobl.us | ||||||||||||||
7 | EXPIRED | Multi System | Wetland Requirement | City | Developer's Maintenance Bond | 11/11/2019 | 4/11/2021 | Too | Old | oldt@cobl.us | 4/11/2021 | |||||||||||||
BONDS & Assign Funds ACTIVE |
Cell Formulas | ||
---|---|---|
Range | Formula | |
A6:A7 | A6 | =IF(K6<$H$1,"EXPIRED",("Active")) |
S6:S7 | S6 | =IF((OR(Q6="",R6="")),"",HYPERLINK(LOWER(R6&LEFT(Q6,1))&"@cobl.us")) |
V6:V7 | V6 | =IF((OR(K6="Until Released",K6="1 year after completion",K6="2 years after completion")),"",K6-$I$1) |
Cells with Conditional Formatting | ||||
---|---|---|---|---|
Cell | Condition | Cell Format | Stop If True | |
D7:E7 | Cell Value | contains "City" | text | YES |
D7:E7 | Cell Value | contains "Develop" | text | YES |
D8:E64401,D5:E6 | Cell Value | contains "City" | text | YES |
D8:E64401,D5:E6 | Cell Value | contains "Develop" | text | YES |
A5:A64401 | Cell Value | ="ACTIVE" | text | YES |
A5:A64401 | Cell Value | ="Inactive" | text | YES |
Cells with Data Validation | ||
---|---|---|
Cell | Allow | Criteria |
J5:J64401 | Any value | |
K5 | Any value | |
L5 | Any value | |
K6:L64401 | Any value | |
A5:A7 | Any value |
5-
Test Test2.xlsm | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | D | H | I | K | ||||||||
5 | Status | Contractor/Owner/Principal | Bond Type | Start Date | Exp/Release Date | Location of Original Copy | |||||||
6 | Active | Asphalt Patch Systems, INC | Street Restoration Bond | 8/14/2019 | Continuous Until Canceled | Permitting Book | |||||||
7 | EXPIRED | Eagle Asphalt Selcoating Co., LLC | Street Restoration Bond | 5/2/2020 | 5/2/2021 | Permitting Book | |||||||
ROW BONDS |
Cell Formulas | ||
---|---|---|
Range | Formula | |
A6:A7 | A6 | =IF(I6<$G$2,"EXPIRED",("Active")) |
Cells with Conditional Formatting | ||||
---|---|---|---|---|
Cell | Condition | Cell Format | Stop If True | |
D6:E7 | Cell Value | contains "City" | text | YES |
D6:E7 | Cell Value | contains "Develop" | text | YES |
D5:E5,D8:E65054 | Cell Value | contains "City" | text | YES |
D5:E5,D8:E65054 | Cell Value | contains "Develop" | text | YES |
A47,C48:C53,A54:A60,A62:A65055,A5:A8 | Cell Value | ="ACTIVE" | text | YES |
A47,C48:C53,A54:A60,A62:A65055,A5:A8 | Cell Value | ="Inactive" | text | YES |
Cells with Data Validation | ||
---|---|---|
Cell | Allow | Criteria |
A5:A7 | Any value | |
H5:H47 | Any value | |
I5:I47 | Any value |
6-
Test Test2.xlsm | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | F | J | K | L | Q | R | S | T | U | V | ||||||||||||
5 | Status | Contractor/Owner/Principal | Project Name/Title | Bond Type | Start Date | Expiration Date | Date Released | Staff Contact First Name | Staff Contact Last Name | Staff Email | Reminder Sent | Was Reminder Sent | Date To Send Reminder | |||||||||||
6 | Destroyed | S & S Construction | Water Mains Contract 70-1 | Performance Bond | 3/13/1970 | 12/31/1980 | 12/31/1980 | Too | Old | oldt@cobl.us | ||||||||||||||
7 | Expired | Clements & Son | 1990 City Hall Remodel | Performance Bond | 11/20/1990 | 4/12/1991 | Too | Old | oldt@cobl.us | 4/12/1991 | ||||||||||||||
BONDS & Assign Funds Inactive |
Cell Formulas | ||
---|---|---|
Range | Formula | |
S6:S7 | S6 | =IF((OR(Q6="",R6="")),"",HYPERLINK(LOWER(R6&LEFT(Q6,1))&"@cobl.us")) |
V6:V7 | V6 | =IF((OR(A6="",A6="Released",A6="N/A",A6="Destroyed")),"",K6-$I$1) |
Cells with Conditional Formatting | ||||
---|---|---|---|---|
Cell | Condition | Cell Format | Stop If True | |
A4617:A64838,A5:A7 | Cell Value | ="ACTIVE" | text | YES |
A4617:A64838,A5:A7 | Cell Value | ="Inactive" | text | YES |
Cells with Data Validation | ||
---|---|---|
Cell | Allow | Criteria |
A5:A7 | Any value | |
J5:J7 | Any value | |
K5:K7 | Any value | |
L5 | Any value | |
L6:L7 | Any value |
VBA Code:
Sub NewMac()
'change macro names to suit
Dim ws As Worksheet
'** SET The Sheet Names - MUST Reflect Each Sheet Name Exactly!
WkSheets = Array("Agreements ACTIVE", "Franchise Agreements ACTIVE", "Bonds & Assign Funds ACTIVE", "Bonds & Assign Funds Inactive")
For Each ws In Sheets(Array("Agreements ACTIVE", "Franchise Agreements ACTIVE", "Bonds & Assign Funds ACTIVE", "Bonds & Assign Funds Inactive"))
ws.Select.Activate
Call AgreementsActive
Next ws
Call FranchiseAgreements
Next ws
Call BondsActive
Next ws
Call BondsInactive
Next ws
End Sub
Public Sub AgreementsActive()
Dim i As Long
Dim OutApp, OutMail As Object
Dim strto, strcc, strbcc, strsub, strbody As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
For i = 6 To Range("R65536").End(xlUp).Row
If Cells(i, 17) <> "Y" Then
If Cells(i, 18) <= Date Then
Set OutMail = OutApp.CreateItem(0)
strto = Cells(i, 15).Value 'email address
strsub = Cells(i, 4).Value & " will expire on " & Cells(i, 7).Value 'email subject
strbody = "Hello " & Cells(i, 13).Value & vbNewLine & "The " & Cells(i, 3).Value & " for the " & Cells(i, 4).Value & " will be expiring on " & Cells(i, 7).Value & ", please review it on the agreements log at:" & vbNewLine & "N:\Everyone\CONTRACTING\Agreements-Bonds LogNEW- the agreements active tab at bottom" & vbNewLine & "to see if it needs to be renewed and place any notes in column H, please." & vbNewLine & "Then if it needs to be renewed, please start the process." & vbNewLine & "Thank you" 'email body
With OutMail
.To = strto
.Subject = strsub
.Body = strbody
.SentOnBehalfOfName = "[I]my email[/I]"
.Send
End With
On Error Resume Next
Cells(i, 16) = "Mail Sent " & Now()
Cells(i, 17) = "Y"
End If
End If
Next
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Public Sub FranchiseAgreements()
Dim i As Long
Dim OutApp, OutMail As Object
Dim strto, strcc, strbcc, strsub, strbody As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
For i = 6 To Range("R65536").End(xlUp).Row
If Cells(i, 17) <> "Y" Then
If Cells(i, 18) <= Date Then
Set OutMail = OutApp.CreateItem(0)
strto = Cells(i, 15).Value 'email address
strsub = Cells(i, 4).Value & " will expire on " & Cells(i, 7).Value 'email subject
strbody = "Hello " & Cells(i, 13).Value & vbNewLine & "The " & Cells(i, 3).Value & " for the " & Cells(i, 4).Value & " will be expiring on " & Cells(i, 7).Value & ", please review it on the agreements log at:" & vbNewLine & "N:\Everyone\CONTRACTING\Agreements-Bonds LogNEW- the franchise active tab at bottom" & vbNewLine & "to see if it needs to be renewed and place any notes in column H, please." & vbNewLine & "Then if it needs to be renewed, please start the process." & vbNewLine & "Thank you" 'email body
With OutMail
.To = strto
.Subject = strsub
.Body = strbody
.SentOnBehalfOfName = "[I]my email[/I]"
.Send
End With
On Error Resume Next
Cells(i, 16) = "Mail Sent " & Now()
Cells(i, 17) = "Y"
End If
End If
Next
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Public Sub BondsActive()
Dim i As Long
Dim OutApp, OutMail As Object
Dim strto, strcc, strbcc, strsub, strbody As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
For i = 6 To Range("V65536").End(xlUp).Row
If Cells(i, 21) <> "Y" Then
If Cells(i, 22) <= Date Then
Set OutMail = OutApp.CreateItem(0)
strto = Cells(i, 19).Value 'email address
strsub = Cells(i, 3).Value & " bond expired on " & Cells(i, 11).Value 'email subject
strbody = "Hello " & Cells(i, 17).Value & vbNewLine & "The " & Cells(i, 6).Value & " for the " & Cells(i, 3).Value & " expired on " & Cells(i, 11).Value & ", please review it on the bonds log at:" & vbNewLine & "N:\Everyone\CONTRACTING\Agreements-Bonds LogNEW- the Bonds & Assign Funds Active tab at bottom" & vbNewLine & "to write and send a release letter and place any notes in column M, please." & vbNewLine & "Then place the date the release letter was sent in column L and email the City Clerk's Office that you released the bond." & vbNewLine & "Thank you" 'email body
With OutMail
.To = strto
.Subject = strsub
.Body = strbody
.SentOnBehalfOfName = "[I]my email[/I]"
.Send
End With
On Error Resume Next
Cells(i, 20) = "Mail Sent " & Now()
Cells(i, 21) = "Y"
End If
End If
Next
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Public Sub BondsInactive()
Dim i As Long
Dim OutApp, OutMail As Object
Dim strto, strcc, strbcc, strsub, strbody As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
For i = 6 To Range("V65536").End(xlUp).Row
If Cells(i, 21) <> "Y" Then
If Cells(i, 22) <= Date Then
Set OutMail = OutApp.CreateItem(0)
strto = Cells(i, 19).Value 'email address
strsub = Cells(i, 3).Value & " bond expired on " & Cells(i, 11).Value 'email subject
strbody = "Hello " & Cells(i, 17).Value & vbNewLine & "The " & Cells(i, 6).Value & " for the " & Cells(i, 3).Value & " expired on " & Cells(i, 11).Value & " and no release date was entered." & vbNewLine & "Please review it on the bonds log at:" & vbNewLine & "N:\Everyone\CONTRACTING\Agreements-Bonds LogNEW- the Bonds & Assign Funds Active tab at bottom" & vbNewLine & "to review and write and send a release letter if needed and place any notes in column M, please." & vbNewLine & "Then place the date that the release letter was sent in column L and email the City Clerk's Office that you released the bond." & vbNewLine & "Thank you" 'email body
With OutMail
.To = strto
.Subject = strsub
.Body = strbody
.SentOnBehalfOfName = "[I]my email[/I]"
.Send
End With
On Error Resume Next
Cells(i, 20) = "Mail Sent " & Now()
Cells(i, 21) = "Y"
End If
End If
Next
Set OutMail = Nothing
Set OutApp = Nothing
End Sub[/CODE]