+ Reply to Thread
Results 1 to 2 of 2

embedding user-defined hyperlink into auto-generated email

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-17-2008
    Location
    Vancouver
    MS-Off Ver
    2002 and XP
    Posts
    117

    embedding user-defined hyperlink into auto-generated email

    hello, I was wondering how to imbed a hyperlink into the body of an automatically generated email.

    Ideally the hyperlink would be based on a cell value to allow a user to cut and paste a file path

    example filepath
    P:\Project Folder\project worksheet.xls


    Here is the current autoemail VBA code I am using. So the filepath would be taken from
    Sheet: Behind The Scenes D4

    Private Sub SimplifiedEmail_Click()
    Dim myOutlok As Object
    Dim myMailItm As Object
    
    Set otlApp = CreateObject("Outlook.Application")
    Set otlNewMail = otlApp.CreateItem(olMailItem)
    fName = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
    
    With otlNewMail
    .To = Sheets("Behind The Scenes").Range("D2")
    .Subject = Sheets("Behind The Scenes").Range("D3") & " " & Sheets("Behind The Scenes").Range("E3")
    .Body = Sheets("Behind The Scenes").Range("D5") & "     " & Sheets("Behind The Scenes").Range("D6") & Chr(10) & Sheets("Behind The Scenes").Range("D7")
    .Send
    End With
    
    otlApp.Quit
    
    Set otlNewMail = Nothing
    Set otlApp = Nothing
    Set otlAttach = Nothing
    Set otlMess = Nothing
    Set otlNSpace = Nothing
    
    End Sub
    Last edited by kuraitori; 11-20-2008 at 08:14 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello kuraitori,

    You need to need to use HTML to include the hyperlink. Here is an example that provides a link to Google...
    Sub EmailWithHyperlink()
    
      Dim refLink As String
      Dim MyApp As Boolean
      Dim olApp As Object
      Dim olEmail As Object
      Dim URL As String
      
      'Outlook constants aren't available using late binding
       Const olMailItem = 0
       
        'Open or Start a new instance of Outlook
         On Error Resume Next
           Set olApp = GetObject(, "Outlook.Application")
             If Err = 429 Then
               MyApp = True
               Set olApp = CreateObject("Outlook.Application")
             End If
         On Error GoTo 0
           
         olApp.Session.Logon
         
        'URL to Google
         URL = Chr$(34) & "http://www.google.com/" & Chr$(34)
         
        'Create HTML Hyperlink
         refLink = "<a href=" & URL & ">Link to Google</a>"
         
        'Create an Outlook Mail Item
         Set olEmail = olApp.CreateItem(olMailItem)
           With olEmail
             .To = "[email protected]"
             .Subject = "Hyperlink test"
             .HTMLBody = "This message hyperlink " & refLink & " will take you to Google."
             .Send
           End With
                         
       olApp.Session.logoff
       If MyApp Then olApp.Quit
     
    'Release Objects
     Set olApp = Nothing
     Set olEmail = Nothing
     
    End Sub
    Sincerely,
    Leith Ross

+ 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