Hi,
I am trying to add a report as an attachment to an email, and this report is updated and sent daily. Therefore I would like to be able to attach the report that is up to date. For example the file name for the report today and date formate would be "Report 11.10.2020". I have tried making the attachment a variable, however I think i have defined it incorrectly (I am getting a 'Path does not exist' error message). I think maybe the date at the end of the file name is not recognised. Below is currently what I have, could anyone please help? Thanks!
Sub MarketReportEmails()
Dim Signature$
Dim olApp As Object
Dim olMail As Object
Dim attachment As String
Dim dte As Date
Set olApp = GetObject(, "Outlook.Application")
Set olMail = olApp.CreateItem(0)
dte = Date
Set attachment = "C:\Users\ans\Documents\Daily report " & dte & ".pdf"
With olMail
.Subject = "Daily Report " & Date
.GetInspector
Signature = olMail.HTMLBody
olMail.HTMLBody = "<body style='font-family:calibri;font-size:11pt'>example" _
& "<br>" _
& "<br>" & Signature
.attachments.Add (attachment)
olMail.Display
End With
End Sub
I am trying to add a report as an attachment to an email, and this report is updated and sent daily. Therefore I would like to be able to attach the report that is up to date. For example the file name for the report today and date formate would be "Report 11.10.2020". I have tried making the attachment a variable, however I think i have defined it incorrectly (I am getting a 'Path does not exist' error message). I think maybe the date at the end of the file name is not recognised. Below is currently what I have, could anyone please help? Thanks!
Sub MarketReportEmails()
Dim Signature$
Dim olApp As Object
Dim olMail As Object
Dim attachment As String
Dim dte As Date
Set olApp = GetObject(, "Outlook.Application")
Set olMail = olApp.CreateItem(0)
dte = Date
Set attachment = "C:\Users\ans\Documents\Daily report " & dte & ".pdf"
With olMail
.Subject = "Daily Report " & Date
.GetInspector
Signature = olMail.HTMLBody
olMail.HTMLBody = "<body style='font-family:calibri;font-size:11pt'>example" _
& "<br>" _
& "<br>" & Signature
.attachments.Add (attachment)
olMail.Display
End With
End Sub