supportsvc
Technical User
Hello,
I found this Outlook Macro, and not ever having worked with Outlook VBScript / Macros, I am unsure how to incorporate the two as one.
Would like to:
1) Send ALL files in the folder (path)
2) Where the LastModifiedDate is today's date only (there will be same files from previous days with datestamps)
This code sends all the files in a folder (path)
This one sends the newest file BUT only one and not all of the files in the folder
Can someone please help and show how to combine the two as one so that one email attaches all of the files n the folder with the lastmodifieddate as today only?
Thank you!
I found this Outlook Macro, and not ever having worked with Outlook VBScript / Macros, I am unsure how to incorporate the two as one.
Would like to:
1) Send ALL files in the folder (path)
2) Where the LastModifiedDate is today's date only (there will be same files from previous days with datestamps)
This code sends all the files in a folder (path)
Code:
Sub SendFilesbyEmail()
Call SendFiles("C:\ReportResults\Email\")
End Sub
Function SendFiles(fldName As String, Optional FileType As String = "*.*")
Dim fName As String
Dim sAttName As String
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Dim olAtt As Outlook.Attachments
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(0) ' email
Set olAtt = olMsg.Attachments
' to send all
fName = Dir(fldName)
'to send only certain extensions
'fName = Dir(fldName & FileType)
Do While Len(fName) > 0
olAtt.Add fldName & fName
sAttName = fName & "<br /> " & sAttName
Debug.Print fName
fName = Dir
Loop
' send message
With olMsg
.Subject = "Daily Orders Reports"
.To = "test@email.com"
.HTMLBody = "Good morning " & ", <br /><br /> Attached are the Daily Orders Reports for your review."
.Display
'.Send
End With
End Function
This one sends the newest file BUT only one and not all of the files in the folder
Code:
Sub SendNewestFiles()
Dim objMail As Outlook.MailItem
Dim fso As Object 'Scripting.FileSystemObject
Dim strFile As String
Dim fsoFile 'As Scripting.File
Dim fsoFldr 'As Scripting.Folder
Dim dtNew As Date, sNew As String
Set fso = CreateObject("Scripting.FileSystemObject")
' path to folder
strFile = "C:\Users\Diane Poremsky\Pictures\"
Set fsoFldr = fso.GetFolder(strFile)
dtNew = Now - 0.25 ' 6 hours ago
For Each fsoFile In fsoFldr.Files
' if date created is less than 6 hours ago
' can use .DateLastModified
If fsoFile.DateCreated > dtNew Then
sNew = fsoFile.Path
Set objMail = Application.CreateItem(olMailItem)
With objMail
.To = "email@address.com"
.BodyFormat = olFormatPlain
.Attachments.Add sNew
.Display ' .send
End With
End If
Next fsoFile
End Sub
Can someone please help and show how to combine the two as one so that one email attaches all of the files n the folder with the lastmodifieddate as today only?
Thank you!