Results 1 to 25 of 25

Use Excel VBA to add a hyperlink to a word document

Threaded View

r0cket88 Use Excel VBA to add a... 12-01-2008, 03:06 PM
Kenneth Hobson Needs a bit more tweaking but... 12-01-2008, 04:28 PM
r0cket88 When I tried your code I get... 12-02-2008, 08:33 AM
Kenneth Hobson I did mine in 2003 using a... 12-02-2008, 09:19 AM
r0cket88 well, I need to file to be a... 12-02-2008, 09:54 AM
r0cket88 I got it working the way you... 12-04-2008, 09:57 AM
Kenneth Hobson There are arguments for one... 12-04-2008, 10:15 AM
r0cket88 Thanks for all the info... 12-04-2008, 10:57 AM
  1. #1
    Registered User
    Join Date
    09-15-2008
    Location
    White Lake, Mi.
    Posts
    18

    Use Excel VBA to add a hyperlink to a word document

    I have a word template that I open (as a new document) with excel VBA.
    This template has bookmarks in it and I can copy and paste text or cell values from excel to the template to fill it out automatically. The one area I am having problems is in trying to create an email hyperlink in one of my bookmarks.

    Does anybody have any suggestions?
    Here is an example of the code I am using that does not work correctly:
    Sub Hyperlink()
    Dim wb As Excel.Workbook
    Dim wdApp As Word.Application
    Dim myDoc As Word.Document
    Dim LinkName As String
    Dim LinkAddress As String
    Dim SPE, SCM, Purch, SQE, Vendor, Veri As Boolean
    
    Set wb = ActiveWorkbook
    Path = wb.Path & "\Test.dotm"
    'On Error GoTo ErrorHandler
    
    'Create a new Word Session
    Set wdApp = CreateObject("Word.Application")
         
    'Open document in word
    Set myDoc = wdApp.Documents.Add(Path)
    
    'Activate word and display document
      With wdApp
        .Visible = True
        .ActiveWindow.WindowState = 0
        .Activate
      End With
    
    LinkName = "Name Here"
    LinkAddress = "Email@Address.com"
      With myDoc.Bookmarks
        .Item("Bookmark2").Range.InsertBefore LinkName
        .Item("Bookmark2").Select
        With Selection
          .Hyperlinks.Add Anchor:=Selection.Range, Address:="Mailto:%20" & _
          LinkAddress, SubAddress:="", ScreenTip:="", TextToDisplay:=LinkName, Target:=""
        End With
      End With
    End Sub
    I have tried several variations on this and cannot seem to get it to work. I can paste the "LinkName" to the bookmark and select the bookmark just fine, but I cant get the hyperlink to attach.

    Any help would be greatly appreciated.
    Rick

    P.S. I am using Office 2007 for this project. The Macro starts and runs in excel which then opens the word document. I wasn't sure if any of that was clear or not.
    Last edited by r0cket88; 12-02-2008 at 08:35 AM. Reason: Update som information

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