Adding an attachment with VBA adds "%20" instead of spaces in the filename.

coveredinbutter

New Member
Joined
Dec 20, 2021
Messages
19
Office Version
  1. 365
Platform
  1. Windows
HI There,

I have some VBA code to grab an excel file and add it to a new e-mail:

VBA Code:
.Attachments.Add varShifBiddingPath & "\Proxys" & "\" & varName1 & varName2 & ".xlsm"

1656530132919.png


This works as expected, opening a new message in outlook with an attachment named "WCC Chat - Full Time.xlsm".

I now have a second PC, and when I run the same macro the attachment is named "WCC%20Chat%20-%20Part%20Time.xlsm".

Since this is a new PC, I'm thinking it must a setting in Outlook that needs to be adjusted?

Any ideas?

Thanks in advance.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Please show all of your code. The issue may not on the line you showed.

What is varShifBiddingPath ?

As you may know, %20 is used in a URL if a file name has spaces, because spaces are not allowed in a URL. So somewhere along the line your file string is getting encoded as a URL. But I don't think Outlook will do that automatically in the VBA.
 
Upvote 0
Please show all of your code. The issue may not on the line you showed.

What is varShifBiddingPath ?

As you may know, %20 is used in a URL if a file name has spaces, because spaces are not allowed in a URL. So somewhere along the line your file string is getting encoded as a URL. But I don't think Outlook will do that automatically in the VBA.
varShifBiddingPath = ThisWorkbook.path

It's a folder on my desktop. Works fine on 1 PC, but not another.
 
Upvote 0
On the PC where it doesn't work, what is the value of ThisWorkbook.path? If it is in a OneDrive folder it is going to come back as a URL.
 
Upvote 0
On the PC where it doesn't work, what is the value of ThisWorkbook.path? If it is in a OneDrive folder it is going to come back as a URL.

It's actually the same folder, on the desktop on both machines. So the sheet is in a folder on the desktop and grabbing the attachment from a sub-folder called "Proxys"
 
Upvote 0
I'm looking for a very specific answer. Please execute the code on the machine with the problem and provide the actual string that is the full path of ThisWorkbook.Path.

I also asked to see all the code.
 
Upvote 0

Forum statistics

Threads
1,215,009
Messages
6,122,674
Members
449,091
Latest member
peppernaut

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