Attachment adds %20 instead of space in filename when sending

Holley

Board Regular
Joined
Dec 11, 2019
Messages
155
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello again! My macro is working as I need it to, except it is not showing the file name correctly as the attachment. It is adding %20 where the spaces should be. This is saved to our OneDrive, so I understand it is because it is a URL. I also have found that I may can save this as a temp file and that would help, but I have no idea how to do that. I have the "send" commented out until I can get the file name correct. Any help would be most appreciated!! Here is my code...

VBA Code:
Dim EmailApp As Outlook.Application
Dim EmailItem As Outlook.MailItem
Dim fileName As String
 
Set EmailApp = New Outlook.Application
Set EmailItem = EmailApp.CreateItem(olMailItem)

fileName = ActiveWorkbook.Name
'If Not InStr(fileName, ".") > 0 Then
 ' MsgBox "File name does not have the correct format."
  'Exit Sub
'Else
'   fileName = Left(fileName, InStr(fileName, ".") - 30)
'End If
Application.Wait (Now + TimeValue("00:00:05"))
With EmailItem
   .To = "michelle@myemail.com"
   .SentOnBehalfOfName = "holley@myemail.com"
   .CC = ""
   .BCC = ""
   .Subject = "Dates"
   .HTMLBody = "Here is this quarters file." & vbNewLine & vbNewLine & "" & vbNewLine & ""
   .Attachments.Add ActiveWorkbook.FullNameURLEncoded
   .Display
   Application.Wait (Now + TimeValue("0:00:00"))
   'Application.SendKeys "%s"
   ActiveWorkbook.Close
    End With
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Maybe this UNTESTED
VBA Code:
Sub MM1()
Dim EmailApp As Outlook.Application
Dim EmailItem As Outlook.MailItem
Dim fileName As String, Str As String
 
Set EmailApp = New Outlook.Application
Set EmailItem = EmailApp.CreateItem(olMailItem)

fileName = ActiveWorkbook.Name
'If Not InStr(fileName, ".") > 0 Then
 ' MsgBox "File name does not have the correct format."
  'Exit Sub
'Else
'   fileName = Left(fileName, InStr(fileName, ".") - 30)
'End If
Application.Wait (Now + TimeValue("00:00:05"))
With EmailItem
   .To = "michelle@myemail.com"
   .SentOnBehalfOfName = "holley@myemail.com"
   .CC = ""
   .BCC = ""
   .Subject = "Dates"
   .HTMLBody = "Here is this quarters file." & vbNewLine & vbNewLine & "" & vbNewLine & ""
   .Attachments.Add ActiveWorkbook.FullNameURLEncoded
   Str = ActiveWorkbook.FullNameURLEncoded
   Str = Replace(Str, "%20", " ")
   .Display
    ActiveWorkbook.Close
    End With
End Sub
 
Upvote 0
Maybe this UNTESTED
VBA Code:
Sub MM1()
Dim EmailApp As Outlook.Application
Dim EmailItem As Outlook.MailItem
Dim fileName As String, Str As String
 
Set EmailApp = New Outlook.Application
Set EmailItem = EmailApp.CreateItem(olMailItem)

fileName = ActiveWorkbook.Name
'If Not InStr(fileName, ".") > 0 Then
 ' MsgBox "File name does not have the correct format."
  'Exit Sub
'Else
'   fileName = Left(fileName, InStr(fileName, ".") - 30)
'End If
Application.Wait (Now + TimeValue("00:00:05"))
With EmailItem
   .To = "michelle@myemail.com"
   .SentOnBehalfOfName = "holley@myemail.com"
   .CC = ""
   .BCC = ""
   .Subject = "Dates"
   .HTMLBody = "Here is this quarters file." & vbNewLine & vbNewLine & "" & vbNewLine & ""
   .Attachments.Add ActiveWorkbook.FullNameURLEncoded
   Str = ActiveWorkbook.FullNameURLEncoded
   Str = Replace(Str, "%20", " ")
   .Display
    ActiveWorkbook.Close
    End With
End Sub
Thanks for your help, but the %20 remains....
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top