- + Load email from template (body, distribution list and so)
- + Look for newest PDF file in set directory
- + Attach that PDF file
- + Strip filename from file/attachment and use it as subject
- ============================================================
- Sub DPRALL()
- '
- Dim objMail As Outlook.MailItem
- Dim fso As Scripting.FileSystemObject
- Dim strFile, sNew, fNew As String, dtNew As Date
- Set fso = New Scripting.FileSystemObject
- strFile = "Z:\11 Admin\02 Operations\01 DPR\"
- Set fsoFldr = fso.GetFolder(strFile)
- For Each fsoFile In fsoFldr.Files
- ' check the extension and age
- If fsoFile.DateLastModified > dtNew And Right(fsoFile.Name, 4) = ".pdf" Then
- fNew = fso.GetBaseName(fsoFile.Name)
- sNew = fsoFile.Path
- dtNew = fsoFile.DateLastModified
- Debug.Print sNew & dtNew
- End If
- Next fsoFile
- 'Create e-mail item
- Set objMail = Application.CreateItemFromTemplate("C:\Users\Administrator\AppData\Roaming\Microsoft\Templates\DPR.oft")
- With objMail
- .BodyFormat = olFormatHTML
- .Attachments.Add sNew
- .Subject = fNew
- .Display
- End With
- End Sub
Recent Pastes