How to set up email to be sent via Excel for projects due within 7 days?Excel VBA - read cell value from code“Run-time error '13': Type Mismatch.” when there is no email addressCopy data from worksheet to html file to mailHow to preserve/retain hyperlinks in email body when using RangetoHTML from ExcelTake the date in one worksheet and find the same date in another worksheet column and return the cell reference for that date to use in a loopTrying to create personalized emails with multiple attachmentsExcel VBA macro to send emails to unique users in rangeexcel VBA code to ignore an email attachment if missing from folderSend email if today's date is within four days of a due dateExcel: Send outlook email based on cell content
creating a ":KeepCursor" command
Recommended PCB layout understanding - ADM2572 datasheet
Extract more than nine arguments that occur periodically in a sentence to use in macros in order to typset
Quoting Keynes in a lecture
Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?
Unexpected behavior of the procedure `Area` on the object 'Polygon'
Terse Method to Swap Lowest for Highest?
Why did the EU agree to delay the Brexit deadline?
Can I say "fingers" when referring to toes?
Lowest total scrabble score
Strong empirical falsification of quantum mechanics based on vacuum energy density
What is the evidence for the "tyranny of the majority problem" in a direct democracy context?
How to explain what's wrong with this application of the chain rule?
Is there a way to get `mathscr' with lower case letters in pdfLaTeX?
Why does a simple loop result in ASYNC_NETWORK_IO waits?
Why should universal income be universal?
Does Doodling or Improvising on the Piano Have Any Benefits?
Does IPv6 have similar concept of network mask?
What exact color does ozone gas have?
Why is it that I can sometimes guess the next note?
Are Captain Marvel's powers affected by Thanos' actions in Infinity War
Why is so much work done on numerical verification of the Riemann Hypothesis?
What does "Scientists rise up against statistical significance" mean? (Comment in Nature)
What happens if you are holding an Iron Flask with a demon inside and walk into an Antimagic Field?
How to set up email to be sent via Excel for projects due within 7 days?
Excel VBA - read cell value from code“Run-time error '13': Type Mismatch.” when there is no email addressCopy data from worksheet to html file to mailHow to preserve/retain hyperlinks in email body when using RangetoHTML from ExcelTake the date in one worksheet and find the same date in another worksheet column and return the cell reference for that date to use in a loopTrying to create personalized emails with multiple attachmentsExcel VBA macro to send emails to unique users in rangeexcel VBA code to ignore an email attachment if missing from folderSend email if today's date is within four days of a due dateExcel: Send outlook email based on cell content
Image of Spreadsheet
I am trying set up email notifications to be sent people in my department whenever there is an upcoming due date within 7 days. Currently the issue is whenever I run the module, it sets up emails for anything that is before the due date. However, I want emails to be set up for projects that are due within 7 days. So if the project is 10 days out, I do not want an email sent, same project where it is already past due.
In addition, I would like the emails to be sent to the person responsible of the project, but not if they have indicated that they already completed the project in Column I.
I have Project names in Column B, Emails in Column F, Due Dates in Column H, and Column K would show "Email Sent" if the script sends the email. If the email has already been sent previously then it would skip that row.
Private Sub Workbook_Open()
Dim OutApp As Object
Dim OutMail As Object
Dim lLastRow As Long
Dim lRow As Long
Dim sSendTo As String
Dim sSendCC As String
Dim sSendBCC As String
Dim sSubject As String
Dim sTemp As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
' Change the following as needed
sSendCC = ""
sSendBCC = ""
sSubject = "Project Log Due Date Reached"
lLastRow = Cells(Rows.Count, 3).End(xlUp).Row
For lRow = 3 To lLastRow
If Cells(lRow, 11) <> "Email Sent" Then
If Cells(lRow, 8) - Date <= 7 And Cells(1Row, 8) - Date > 0 Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = Cells(1Row, 6)
If sSendCC > "" Then .CC = sSendCC
If sSendBCC > "" Then .BCC = sSendBCC
.Subject = sSubject
sTemp = "Hello!" & vbCrLf & vbCrLf
sTemp = sTemp & "The due date has been reached "
sTemp = sTemp & "for this project:" & vbCrLf & vbCrLf
' Assumes project name is in column B
sTemp = sTemp & " " & Cells(lRow, 2)
sTemp = sTemp & "Please take the appropriate"
sTemp = sTemp & "action." & vbCrLf & vbCrLf
sTemp = sTemp & "Thank you!" & vbCrLf
.Body = sTemp
' Change the following to .Send if you want to
' send the message without reviewing first
.Send
End With
Set OutMail = Nothing
Cells(lRow, 11) = "Email Sent"
Cells(lRow, 12) = "E-mail sent on: " & Now()
End If
End If
Next lRow
Set OutApp = Nothing
End Sub
excel vba
add a comment |
Image of Spreadsheet
I am trying set up email notifications to be sent people in my department whenever there is an upcoming due date within 7 days. Currently the issue is whenever I run the module, it sets up emails for anything that is before the due date. However, I want emails to be set up for projects that are due within 7 days. So if the project is 10 days out, I do not want an email sent, same project where it is already past due.
In addition, I would like the emails to be sent to the person responsible of the project, but not if they have indicated that they already completed the project in Column I.
I have Project names in Column B, Emails in Column F, Due Dates in Column H, and Column K would show "Email Sent" if the script sends the email. If the email has already been sent previously then it would skip that row.
Private Sub Workbook_Open()
Dim OutApp As Object
Dim OutMail As Object
Dim lLastRow As Long
Dim lRow As Long
Dim sSendTo As String
Dim sSendCC As String
Dim sSendBCC As String
Dim sSubject As String
Dim sTemp As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
' Change the following as needed
sSendCC = ""
sSendBCC = ""
sSubject = "Project Log Due Date Reached"
lLastRow = Cells(Rows.Count, 3).End(xlUp).Row
For lRow = 3 To lLastRow
If Cells(lRow, 11) <> "Email Sent" Then
If Cells(lRow, 8) - Date <= 7 And Cells(1Row, 8) - Date > 0 Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = Cells(1Row, 6)
If sSendCC > "" Then .CC = sSendCC
If sSendBCC > "" Then .BCC = sSendBCC
.Subject = sSubject
sTemp = "Hello!" & vbCrLf & vbCrLf
sTemp = sTemp & "The due date has been reached "
sTemp = sTemp & "for this project:" & vbCrLf & vbCrLf
' Assumes project name is in column B
sTemp = sTemp & " " & Cells(lRow, 2)
sTemp = sTemp & "Please take the appropriate"
sTemp = sTemp & "action." & vbCrLf & vbCrLf
sTemp = sTemp & "Thank you!" & vbCrLf
.Body = sTemp
' Change the following to .Send if you want to
' send the message without reviewing first
.Send
End With
Set OutMail = Nothing
Cells(lRow, 11) = "Email Sent"
Cells(lRow, 12) = "E-mail sent on: " & Now()
End If
End If
Next lRow
Set OutApp = Nothing
End Sub
excel vba
Can you edit your question - link here - and specify what problem(s) you are having?
– BigBen
Mar 8 at 1:49
And add some sample data
– Ricardo Diaz
Mar 8 at 2:06
and get rid of this:On Error Resume Nextthere's no need for it in this code and it will hide real issues that may arise and can be handled differently .... in this line :If Cells(lRow, 7) <= 7 Then, are you sure you have the right math in column G to calculate the days?
– Scott Holtzman
Mar 8 at 2:31
add a comment |
Image of Spreadsheet
I am trying set up email notifications to be sent people in my department whenever there is an upcoming due date within 7 days. Currently the issue is whenever I run the module, it sets up emails for anything that is before the due date. However, I want emails to be set up for projects that are due within 7 days. So if the project is 10 days out, I do not want an email sent, same project where it is already past due.
In addition, I would like the emails to be sent to the person responsible of the project, but not if they have indicated that they already completed the project in Column I.
I have Project names in Column B, Emails in Column F, Due Dates in Column H, and Column K would show "Email Sent" if the script sends the email. If the email has already been sent previously then it would skip that row.
Private Sub Workbook_Open()
Dim OutApp As Object
Dim OutMail As Object
Dim lLastRow As Long
Dim lRow As Long
Dim sSendTo As String
Dim sSendCC As String
Dim sSendBCC As String
Dim sSubject As String
Dim sTemp As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
' Change the following as needed
sSendCC = ""
sSendBCC = ""
sSubject = "Project Log Due Date Reached"
lLastRow = Cells(Rows.Count, 3).End(xlUp).Row
For lRow = 3 To lLastRow
If Cells(lRow, 11) <> "Email Sent" Then
If Cells(lRow, 8) - Date <= 7 And Cells(1Row, 8) - Date > 0 Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = Cells(1Row, 6)
If sSendCC > "" Then .CC = sSendCC
If sSendBCC > "" Then .BCC = sSendBCC
.Subject = sSubject
sTemp = "Hello!" & vbCrLf & vbCrLf
sTemp = sTemp & "The due date has been reached "
sTemp = sTemp & "for this project:" & vbCrLf & vbCrLf
' Assumes project name is in column B
sTemp = sTemp & " " & Cells(lRow, 2)
sTemp = sTemp & "Please take the appropriate"
sTemp = sTemp & "action." & vbCrLf & vbCrLf
sTemp = sTemp & "Thank you!" & vbCrLf
.Body = sTemp
' Change the following to .Send if you want to
' send the message without reviewing first
.Send
End With
Set OutMail = Nothing
Cells(lRow, 11) = "Email Sent"
Cells(lRow, 12) = "E-mail sent on: " & Now()
End If
End If
Next lRow
Set OutApp = Nothing
End Sub
excel vba
Image of Spreadsheet
I am trying set up email notifications to be sent people in my department whenever there is an upcoming due date within 7 days. Currently the issue is whenever I run the module, it sets up emails for anything that is before the due date. However, I want emails to be set up for projects that are due within 7 days. So if the project is 10 days out, I do not want an email sent, same project where it is already past due.
In addition, I would like the emails to be sent to the person responsible of the project, but not if they have indicated that they already completed the project in Column I.
I have Project names in Column B, Emails in Column F, Due Dates in Column H, and Column K would show "Email Sent" if the script sends the email. If the email has already been sent previously then it would skip that row.
Private Sub Workbook_Open()
Dim OutApp As Object
Dim OutMail As Object
Dim lLastRow As Long
Dim lRow As Long
Dim sSendTo As String
Dim sSendCC As String
Dim sSendBCC As String
Dim sSubject As String
Dim sTemp As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
' Change the following as needed
sSendCC = ""
sSendBCC = ""
sSubject = "Project Log Due Date Reached"
lLastRow = Cells(Rows.Count, 3).End(xlUp).Row
For lRow = 3 To lLastRow
If Cells(lRow, 11) <> "Email Sent" Then
If Cells(lRow, 8) - Date <= 7 And Cells(1Row, 8) - Date > 0 Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = Cells(1Row, 6)
If sSendCC > "" Then .CC = sSendCC
If sSendBCC > "" Then .BCC = sSendBCC
.Subject = sSubject
sTemp = "Hello!" & vbCrLf & vbCrLf
sTemp = sTemp & "The due date has been reached "
sTemp = sTemp & "for this project:" & vbCrLf & vbCrLf
' Assumes project name is in column B
sTemp = sTemp & " " & Cells(lRow, 2)
sTemp = sTemp & "Please take the appropriate"
sTemp = sTemp & "action." & vbCrLf & vbCrLf
sTemp = sTemp & "Thank you!" & vbCrLf
.Body = sTemp
' Change the following to .Send if you want to
' send the message without reviewing first
.Send
End With
Set OutMail = Nothing
Cells(lRow, 11) = "Email Sent"
Cells(lRow, 12) = "E-mail sent on: " & Now()
End If
End If
Next lRow
Set OutApp = Nothing
End Sub
excel vba
excel vba
edited Mar 8 at 18:54
Seany
asked Mar 8 at 1:47
SeanySeany
11
11
Can you edit your question - link here - and specify what problem(s) you are having?
– BigBen
Mar 8 at 1:49
And add some sample data
– Ricardo Diaz
Mar 8 at 2:06
and get rid of this:On Error Resume Nextthere's no need for it in this code and it will hide real issues that may arise and can be handled differently .... in this line :If Cells(lRow, 7) <= 7 Then, are you sure you have the right math in column G to calculate the days?
– Scott Holtzman
Mar 8 at 2:31
add a comment |
Can you edit your question - link here - and specify what problem(s) you are having?
– BigBen
Mar 8 at 1:49
And add some sample data
– Ricardo Diaz
Mar 8 at 2:06
and get rid of this:On Error Resume Nextthere's no need for it in this code and it will hide real issues that may arise and can be handled differently .... in this line :If Cells(lRow, 7) <= 7 Then, are you sure you have the right math in column G to calculate the days?
– Scott Holtzman
Mar 8 at 2:31
Can you edit your question - link here - and specify what problem(s) you are having?
– BigBen
Mar 8 at 1:49
Can you edit your question - link here - and specify what problem(s) you are having?
– BigBen
Mar 8 at 1:49
And add some sample data
– Ricardo Diaz
Mar 8 at 2:06
And add some sample data
– Ricardo Diaz
Mar 8 at 2:06
and get rid of this:
On Error Resume Next there's no need for it in this code and it will hide real issues that may arise and can be handled differently .... in this line :If Cells(lRow, 7) <= 7 Then, are you sure you have the right math in column G to calculate the days?– Scott Holtzman
Mar 8 at 2:31
and get rid of this:
On Error Resume Next there's no need for it in this code and it will hide real issues that may arise and can be handled differently .... in this line :If Cells(lRow, 7) <= 7 Then, are you sure you have the right math in column G to calculate the days?– Scott Holtzman
Mar 8 at 2:31
add a comment |
2 Answers
2
active
oldest
votes
(Building reputation)
Seany, Scott's right - take out the "On Error Resume Next" statement as this suppresses errors you'd rather see and troubleshoot at design time. And, you said Column F; which when using the Cells property, the column is the second parameter and you have "7" where "F" would be "6."
For comparing dates, I'd suggest DateDiff
Ex:
DateDiff("d", ws.Cells(1, 1).Value, ws.Cells(1, 1).Value + 7)
add a comment |
Please make a helper column in free column say Land put the formula =TODAY()-G2and draw down. Replace your following lines
For lRow = 3 To lLastRow
If Cells(lRow, 10) <> "Email Sent" Then
If Cells(lRow, 7) <= 7 Then
Set OutMail = OutApp.CreateItem(0)
With
For lRow = 3 To lLastRow
If Cells(lRow, 10) <> "Email Sent" Then
If (Cells(lRow, 12) >= -7) And (Cells(lRow, 12) <= 0) Then
Set OutMail = OutApp.CreateItem(0)
It works for me. You can also follow any other logic based on this logic.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055584%2fhow-to-set-up-email-to-be-sent-via-excel-for-projects-due-within-7-days%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
(Building reputation)
Seany, Scott's right - take out the "On Error Resume Next" statement as this suppresses errors you'd rather see and troubleshoot at design time. And, you said Column F; which when using the Cells property, the column is the second parameter and you have "7" where "F" would be "6."
For comparing dates, I'd suggest DateDiff
Ex:
DateDiff("d", ws.Cells(1, 1).Value, ws.Cells(1, 1).Value + 7)
add a comment |
(Building reputation)
Seany, Scott's right - take out the "On Error Resume Next" statement as this suppresses errors you'd rather see and troubleshoot at design time. And, you said Column F; which when using the Cells property, the column is the second parameter and you have "7" where "F" would be "6."
For comparing dates, I'd suggest DateDiff
Ex:
DateDiff("d", ws.Cells(1, 1).Value, ws.Cells(1, 1).Value + 7)
add a comment |
(Building reputation)
Seany, Scott's right - take out the "On Error Resume Next" statement as this suppresses errors you'd rather see and troubleshoot at design time. And, you said Column F; which when using the Cells property, the column is the second parameter and you have "7" where "F" would be "6."
For comparing dates, I'd suggest DateDiff
Ex:
DateDiff("d", ws.Cells(1, 1).Value, ws.Cells(1, 1).Value + 7)
(Building reputation)
Seany, Scott's right - take out the "On Error Resume Next" statement as this suppresses errors you'd rather see and troubleshoot at design time. And, you said Column F; which when using the Cells property, the column is the second parameter and you have "7" where "F" would be "6."
For comparing dates, I'd suggest DateDiff
Ex:
DateDiff("d", ws.Cells(1, 1).Value, ws.Cells(1, 1).Value + 7)
answered Mar 8 at 3:50
J VBAJ VBA
16715
16715
add a comment |
add a comment |
Please make a helper column in free column say Land put the formula =TODAY()-G2and draw down. Replace your following lines
For lRow = 3 To lLastRow
If Cells(lRow, 10) <> "Email Sent" Then
If Cells(lRow, 7) <= 7 Then
Set OutMail = OutApp.CreateItem(0)
With
For lRow = 3 To lLastRow
If Cells(lRow, 10) <> "Email Sent" Then
If (Cells(lRow, 12) >= -7) And (Cells(lRow, 12) <= 0) Then
Set OutMail = OutApp.CreateItem(0)
It works for me. You can also follow any other logic based on this logic.
add a comment |
Please make a helper column in free column say Land put the formula =TODAY()-G2and draw down. Replace your following lines
For lRow = 3 To lLastRow
If Cells(lRow, 10) <> "Email Sent" Then
If Cells(lRow, 7) <= 7 Then
Set OutMail = OutApp.CreateItem(0)
With
For lRow = 3 To lLastRow
If Cells(lRow, 10) <> "Email Sent" Then
If (Cells(lRow, 12) >= -7) And (Cells(lRow, 12) <= 0) Then
Set OutMail = OutApp.CreateItem(0)
It works for me. You can also follow any other logic based on this logic.
add a comment |
Please make a helper column in free column say Land put the formula =TODAY()-G2and draw down. Replace your following lines
For lRow = 3 To lLastRow
If Cells(lRow, 10) <> "Email Sent" Then
If Cells(lRow, 7) <= 7 Then
Set OutMail = OutApp.CreateItem(0)
With
For lRow = 3 To lLastRow
If Cells(lRow, 10) <> "Email Sent" Then
If (Cells(lRow, 12) >= -7) And (Cells(lRow, 12) <= 0) Then
Set OutMail = OutApp.CreateItem(0)
It works for me. You can also follow any other logic based on this logic.
Please make a helper column in free column say Land put the formula =TODAY()-G2and draw down. Replace your following lines
For lRow = 3 To lLastRow
If Cells(lRow, 10) <> "Email Sent" Then
If Cells(lRow, 7) <= 7 Then
Set OutMail = OutApp.CreateItem(0)
With
For lRow = 3 To lLastRow
If Cells(lRow, 10) <> "Email Sent" Then
If (Cells(lRow, 12) >= -7) And (Cells(lRow, 12) <= 0) Then
Set OutMail = OutApp.CreateItem(0)
It works for me. You can also follow any other logic based on this logic.
edited Mar 8 at 4:46
answered Mar 8 at 4:28
skkakkarskkakkar
2,2312924
2,2312924
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055584%2fhow-to-set-up-email-to-be-sent-via-excel-for-projects-due-within-7-days%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you edit your question - link here - and specify what problem(s) you are having?
– BigBen
Mar 8 at 1:49
And add some sample data
– Ricardo Diaz
Mar 8 at 2:06
and get rid of this:
On Error Resume Nextthere's no need for it in this code and it will hide real issues that may arise and can be handled differently .... in this line :If Cells(lRow, 7) <= 7 Then, are you sure you have the right math in column G to calculate the days?– Scott Holtzman
Mar 8 at 2:31