1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Creating dynamic hyperlinks in Word - embedding fields inside fields using VB

Discussion in 'Software Development' started by Gavrilo Princip, Jan 7, 2009.

Thread Status:
Not open for further replies.
  1. Gavrilo Princip

    Gavrilo Princip Thread Starter

    Jan 7, 2009
    I am trying to create links to specific locations with each document between two documents. The document names will change. I can update the current name of the other document by creating a custom property called "otherDoc". I have solved most problems, however, I am unable to insert a field into the address of the link (to make the link dynamic) without utilizing the showfieldcodes command (which is very memory and time consuming since the documents I am working on are very large). Below is my code. I was wondering if there is any way to set the address as a field? Or somehow input an address and it would be understood by word to be field.

    Sub link_to_other()

    'pastes hyperlink to the other document
    Selection.PasteSpecial Link:=True, DataType:=wdPasteHyperlink, Placement:= _
    wdInLine, DisplayAsIcon:=False

    'selects the hyperlink that was just inserted
    Set myField = Selection.PreviousField

    'creates variables
    Dim temp_address As String
    Dim temp_subaddress As String

    'sets variables
    temp_address = ActiveDocument.CustomDocumentProperties("otherDoc").Value & ".doc"
    temp_subaddress = Selection.Range.Hyperlinks(1).SubAddress

    'changes the hyperlink the the dynamic value
    Set SCut = ActiveDocument.Hyperlinks.Add( _
    Anchor:=Selection.Range, _
    Address:=temp_address, SubAddress:=temp_subaddress)
    End Sub
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/787901

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice