+ Reply to Thread
Results 1 to 6 of 6

How to create email, adn add hyperlink for workbook filepath?

Hybrid View

Rerock How to create email, adn add... 09-01-2012, 11:04 AM
BuckoAk Re: How to create email, adn... 09-03-2012, 05:03 PM
BuckoAk Re: How to create email, adn... 09-07-2012, 12:33 PM
Mike1001 Re: How to create email, adn... 09-07-2012, 12:43 PM
BuckoAk Re: How to create email, adn... 09-07-2012, 09:28 PM
BuckoAk Re: How to create email, adn... 09-11-2012, 02:51 AM
  1. #1
    Forum Contributor
    Join Date
    07-22-2009
    Location
    Minneapolis, MN
    MS-Off Ver
    2016
    Posts
    220

    How to create email, adn add hyperlink for workbook filepath?

    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:

    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!

  2. #2
    Forum Contributor
    Join Date
    08-09-2012
    Location
    Anch, Alaska
    MS-Off Ver
    2003, 2010, 2013
    Posts
    131

    Re: How to create email, adn add hyperlink for workbook filepath?

    Give this a try.

    Sub Send_Email_to_Engineering_For_Review()
    '
    ' Send_Email_to_Engineering_For_Review Macro
    '
    
    'ThisWorkbook.Path
     Dim OutApp As Object
        Dim OutMail As Object
        
        strbody = "Click on this link to open the file : " & _
                  "<A HREF=""file://" & ActiveWorkbook.FullName & _
                      """>Link to the file</A>"
                      
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
    
        On Error Resume Next
        With OutMail
            .To = Range("Sheet1!A1")
            .Subject = "Please Review"
            .HTMLBody = strbody
            
                    
            If Send = True Then
                .Send
            Else
                .Display
            End If
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    Last edited by BuckoAk; 09-03-2012 at 05:43 PM. Reason: Revised callout typo
    Give Credit When Credit Is Due - Click On the Star
    Be Sure To Mark Your Post [Solved] When You Get Your Answer

  3. #3
    Forum Contributor
    Join Date
    08-09-2012
    Location
    Anch, Alaska
    MS-Off Ver
    2003, 2010, 2013
    Posts
    131

    Re: How to create email, adn add hyperlink for workbook filepath?

    If your happy with your answer, be sure to mark you post as [Solved].
    At the Top Right of your Post You can:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    You can also give credit by clicking on the Star at the bottom left of the supporting post.

  4. #4
    Forum Contributor
    Join Date
    01-31-2007
    Location
    Aschaffenburg, Germany
    MS-Off Ver
    Office 2013
    Posts
    104

    Re: How to create email, adn add hyperlink for workbook filepath?

    Hey BuckoAk, that's great!
    It doesn't look perfect, since the prefix and suffix are shown as well in the e-mail, but it works !!!!
    Mike 1001
    _________________________
    Let's keep trying, one day we'll succeed!

  5. #5
    Forum Contributor
    Join Date
    08-09-2012
    Location
    Anch, Alaska
    MS-Off Ver
    2003, 2010, 2013
    Posts
    131

    Re: How to create email, adn add hyperlink for workbook filepath?

    Mike,

    I didn't catch it at first, what do you mean the prefix and suffix are shown.
    Are you not seeing this below (See Image) when the email is created? Did you adjust the code by chance?
    Attached Images Attached Images

  6. #6
    Forum Contributor
    Join Date
    08-09-2012
    Location
    Anch, Alaska
    MS-Off Ver
    2003, 2010, 2013
    Posts
    131

    Re: How to create email, adn add hyperlink for workbook filepath?

    If your happy with your answer, be sure to mark you post as [Solved].
    At the Top Right of your Post You can:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    You can also give credit by clicking on the Star at the bottom left of the supporting post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1