VBA 将空格替换为 %20

问题描述 投票:0回答:1

我的文件名包含空格,当将文件附加到我的电子邮件时,这些空格会被替换为 %20。

ActiveWorkbook.SaveAs filename:="CLIENT NAME - OUR NAME- Statement of Account as of " & Format(Now(), "MM-DD-YY") & ".xlsx"


       
Dim OutlookApp As Object
Dim OutlookMessage As Object
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMessage = OutlookApp.CreateItem(0)

With OutlookMessage
    .To = " CLIENT EMAIL "
    .CC = " MY EMAIL "
    .Subject = "CLIENT NAME - OUR NAME - Statement of Account"
    .Body = "Dear Valued Client," & vbNewLine & vbNewLine & "Attached is your weekly statement of account." & vbNewLine & vbNewLine & "Please let us know if you have any questions" & vbNewLine & vbNewLine & "Thank you," & vbNewLine & "Accounts Receivable Team"
    .Attachments.Add ActiveWorkbook.FullName
    .Display
End With
Set OutlookMessage = Nothing
Set OutlookApp = Nothing

将附件添加到我的电子邮件时,它显示“CLIENTNAME%20-%20OUR%20NAME%20-%20-Statement%20of%20Account%20as%20of%20Date%20.xlsx,但文件本身可以正确保存空格。当我手动附加文件时,它也会正确保存空格。

excel vba filenames email-attachments
1个回答
0
投票

处理 OneDrive/SharePoint 中的文件时,我发现使用 Attachments.Add 表达式的“DisplayName”参数将导致文件名包含空格(例如,不是 URL 编码的文件名)。在您的示例中,只需替换

ActiveWorkbook.FullName

ActiveWorkbook.FullName, , , ActiveWorkbook.Name
© www.soinside.com 2019 - 2024. All rights reserved.