VBA Code to Send Only Today's Entries

Justinian

Well-known Member
Joined
Aug 9, 2009
Messages
1,557
Office Version
  1. 365
Platform
  1. Windows
I have a basic spreadsheet to track when vendor visit our property. It is a running list (as seen below) and I want to install a macro that will e-mail only the contents of the rows with today's date to an assigned recipient.

For example, using the data below, I would like the macro to open an Outlook e-mail and send the contents of rows 3 and 4 since they are the only rows with today's date. I know how to run a macro to e-mail the entire workbook or worksheet but not the individual rows of data. How would I do this?

Outside Contractor - Daily Log.xlsm
ABC
1OC NameDateUnit Code
2Vendor A06/29/2095-96
3Vendor B06/30/20105-45
4Vendor C06/30/20105-97
5
6
Sheet1
 
Forget the above, I do not know how to explain to you that you filter the data.

Try this new macro.

VBA Code:
Sub Send_Today_Entries()
  Dim sh1 As Worksheet, sh2 As Worksheet, wb2 As Workbook
  Dim sName As String, i As Long, j As Long
  
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  Set sh1 = Sheets("Sheet1")
  
  Set wb2 = Workbooks.Add
  Set sh2 = wb2.Sheets(1)
  sh1.Rows(1).Copy sh2.Range("A1")
  j = 2
  For i = 2 To sh1.Range("B" & Rows.Count).End(3).Row
    If sh1.Range("B" & i).Value = Date Then
      sh1.Rows(i).Copy sh2.Rows(j)
      j = j + 1
    End If
  Next
  
  With ThisWorkbook
    sName = .Path & "\" & Left(.Name, InStrRev(.Name, ".") - 1) & ".xlsx"
    wb2.SaveAs sName
    wb2.Close False
  End With
      
  With CreateObject("outlook.application").createitem(0)
    .To = "email@gmail.com"
    .Subject = "Subject"
    .body = "Body"
    .Attachments.Add sName
    .display 'use .Send to send
  End With
  
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I understand what you want. Here is the code:

Sub Macro1()

' Macro1 Macro
Selection.AutoFilter
Range("C3").Select
Selection.AutoFilter
Selection.AutoFilter
Range("B5").Select
ActiveSheet.Range("$A$1:$C$8").AutoFilter Field:=2, Criteria1:=1, Operator _
:=11, Criteria2:=0, SubField:=0
End Sub
 
Upvote 0
The new code you just wrote attaches the workbook to the e-mail but it does not put the rows with today's date into the e-mail body, which is what I am trying to do.
 
Upvote 0
but it does not put the rows with today's date into the e-mail body
You didn't mention that you wanted the data in the body of the email.

To put a range of cells in the body of the email you need a different macro. check the following link.
 
Upvote 0
The mail range macro works but it does not automatically highlight today's dates. I can record a macro to filter out only today's date but I do not know where to put it inside the Ron Bruin macro.
 
Upvote 0
I mentioned it in post #1.

Could you comment on where you mention you want the rows in the body of the email?

I have a basic spreadsheet to track when vendor visit our property. It is a running list (as seen below) and I want to install a macro that will e-mail only the contents of the rows with today's date to an assigned recipient.

For example, using the data below, I would like the macro to open an Outlook e-mail and send the contents of rows 3 and 4 since they are the only rows with today's date. I know how to run a macro to e-mail the entire workbook or worksheet but not the individual rows of data. How would I do this?
 
Upvote 0
I have a basic spreadsheet to track when vendor visit our property. It is a running list (as seen below) and I want to install a macro that will e-mail only the contents of the rows with today's date to an assigned recipient.

For example, using the data below, I would like the macro to open an Outlook e-mail and send the contents of rows 3 and 4 since they are the only rows with today's date. I know how to run a macro to e-mail the entire workbook or worksheet but not the individual rows of data. How would I do this?
 
Upvote 0
I would like the macro to open an Outlook e-mail and send the contents of rows 3 and 4 since they are the only rows with today's date.
Sorry, but I do not see that there expresses that you want the content of the cells within the body of the email.
But maybe I am wrong.
 
Upvote 0
It says it right here:

send the contents of rows 3 and 4
 
Upvote 0

Forum statistics

Threads
1,215,745
Messages
6,126,632
Members
449,323
Latest member
Smarti1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top