'VBA Replace Whitespace with Underscore for All Files in Folder
I have a script that loops through all the PDFs in a folder and attaches them to an email. However if there are spaces in the pdf names it will replaces this with a %20.
How can I either rename all the pdfs and the very excel file the script is in to be without whitespace without saving new versions of each, or rename the pdfs and the excel file as it is being attached?
With my current code, I get the error: Invalid call or procedure:
Below is my code I tried with the renaming attempt:
Do While Len(file_name) > 0
Name ThisWorkbook.path & "/" & file_name As ThisWorkbook.path & "/" & Replace(file_name, " ", "_")
If Right(file_name, 3) = "pdf" Then
.attachments.Add ThisWorkbook.path & "/" & file_name
file_name = Dir
Else
End If
Loop
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|