VB 41
Excel VBA DPR By mike on 28th March 2021 03:51:28 PM
  1. + Load email from template (body, distribution list and so)
  2. + Look for newest PDF file in set directory
  3. + Attach that PDF file
  4. + Strip filename from file/attachment and use it as subject
  5.  
  6. ============================================================
  7.  
  8.  
  9. Sub DPRALL()
  10. '
  11. Dim objMail As Outlook.MailItem
  12. Dim fso As Scripting.FileSystemObject
  13. Dim strFile, sNew, fNew As String, dtNew As Date
  14. Set fso = New Scripting.FileSystemObject
  15.  
  16. strFile = "Z:\11 Admin\02 Operations\01 DPR\"
  17. Set fsoFldr = fso.GetFolder(strFile)
  18.      
  19. For Each fsoFile In fsoFldr.Files
  20. ' check the extension and age
  21.   If fsoFile.DateLastModified > dtNew And Right(fsoFile.Name, 4) = ".pdf" Then
  22.     fNew = fso.GetBaseName(fsoFile.Name)
  23.     sNew = fsoFile.Path
  24.     dtNew = fsoFile.DateLastModified
  25.     Debug.Print sNew & dtNew
  26.   End If
  27. Next fsoFile
  28.  
  29. 'Create e-mail item
  30. Set objMail = Application.CreateItemFromTemplate("C:\Users\Administrator\AppData\Roaming\Microsoft\Templates\DPR.oft")
  31. With objMail
  32. .BodyFormat = olFormatHTML
  33. .Attachments.Add sNew
  34. .Subject = fNew
  35. .Display
  36. End With
  37. End Sub

Hasta la pasta! is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.