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

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Gavrilo Princip

Thread Starter
Joined
Jan 7, 2009
Messages
1
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
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Staff online

Top