Hi!
I'm pretty new with VBA and trying to take some initiative with fixing some of the broken macros. Currently the file I'm using correctly converts an excel tab into a pdf document and saves it into the correct folder, with the file name having some spaces. I'm also able to attach the pdf file to the email but the file name now has %20 between spaces for e.g. Daily Summary 20210409 is now Daily%20Summary%2020210409. I've unsuccessfully tried using Application.WorksheetFunction.Substitute( X, " ", "%20"). Any help is much appreciated:
>>> use code - tags <<<
I'm pretty new with VBA and trying to take some initiative with fixing some of the broken macros. Currently the file I'm using correctly converts an excel tab into a pdf document and saves it into the correct folder, with the file name having some spaces. I'm also able to attach the pdf file to the email but the file name now has %20 between spaces for e.g. Daily Summary 20210409 is now Daily%20Summary%2020210409. I've unsuccessfully tried using Application.WorksheetFunction.Substitute( X, " ", "%20"). Any help is much appreciated:
>>> use code - tags <<<
Code:
Dim OutApp As Object
Dim OutMail As Object
Dim rng As Range
Dim StrBody1, StrBody2 As String
Dim LastRow As Long
Dim i As Integer
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'Set filepath for attachments
Let Path = Application.ActiveWorkbook.Path
Let Report_Date = Format(Sheets("Report").Range("Report_Date"), "YYYYMMDD")
Let Path_Perf = Path & "\Daily Summary " & (Report_Date) & ".pdf"
.
.
.
.
'Compose email
On Error Resume Next
With OutMail
.Display
.To = Sheets("Email Report").Range("RecipientsTo")
.CC = Sheets("Email Report").Range("RecipientsCC")
.BCC = ""
.Subject = Sheets("Email Report").Range("Email_Subject")
.HTMLBody = StrBody1 & _
RangetoHTML(rng) & _
StrBody2 & "<br>" & _
.HTMLBody
.Attachments.Add Path_Perf
'.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Attachments
Last edited by a moderator: