Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50238

File path hyperlink in email, how to replace spaces w/ "%20"?

$
0
0
Hi!
I'm attempting to put a hyperlink in an automatic email that the recipient can click and go to the folder where the file is located on our network.

There are two tricky parts to this:
1) The path is not a fixed location (the excel file is for pricing bids/quotes, and each project has its own folder).
2) The names of the folders contain spaces.

This code works great provided there are no spaces in the file path:

Code:

Sub Send_Email_to_Engineering_For_Review()
'
' Send_Email_to_Engineering_For_Review Macro
'

'ThisWorkbook.Path
 Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
        .To = Range("Sheet1!A1")
        .Subject = "Please Review"
        .Body = "file://" & ThisWorkbook.Path
       
        If Send = True Then
            .Send
        Else
            .Display
        End If
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

From my searches, if the filepath contains spaces (which ours does), they need to be replaced with "%20".

Running a test with the current code, the hyperlink breaks at the first 'space', then the remainder of the filepath is simply text (not blue and underlined).

Does anyone know a fix, or have an alternative solution altogether? I'm open to anything as long as it works!

Thanks!

Viewing all articles
Browse latest Browse all 50238

Trending Articles