Multiple Hyperlinks in Table Cell

N

nfantis

Hi,

Thanks in advance for any help. I am trying to add multiple
hyperlinks, separated by a return, in a table cell.

I can add the hyperlink:

objRange = objTable.Cell(5, 2).Range
objDoc.Hyperlinks.Add(objRange, strEachLink(1), , , strEachLink(0))

Now I need some spacing between this link and the following link, so I
have tried this:

objTable.Cell(5, 2).Range.Text += Chr(11)

However, that removes the hyperlink from the text. Anytime I try to
append any text to the cell, it removes the hyperlink.

What am I missing or where is my logic wrong causing this to not work?
 
H

Helmut Weber

Hi nfantis,

like that:

Sub Test1x()
Dim rTmp As Range
With ActiveDocument.Tables(1).Range.Cells(1)
Set rTmp = .Range
rTmp.End = rTmp.End - 1
rTmp.InsertAfter Chr(11)
' or rTmp.InsertAfter Chr(13)
rTmp.Collapse Direction:=wdCollapseEnd
ActiveDocument.Hyperlinks.Add _
Anchor:=rTmp, _
Address:="Doc2.doc", _
SubAddress:="", _
ScreenTip:="", _
TextToDisplay:="Doc2.doc"
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
N

nfantis

Hi nfantis,

like that:

Sub Test1x()
Dim rTmp As Range
With ActiveDocument.Tables(1).Range.Cells(1)
   Set rTmp = .Range
   rTmp.End = rTmp.End - 1
   rTmp.InsertAfter Chr(11)
   ' or rTmp.InsertAfter Chr(13)
   rTmp.Collapse Direction:=wdCollapseEnd
   ActiveDocument.Hyperlinks.Add _
   Anchor:=rTmp, _
   Address:="Doc2.doc", _
   SubAddress:="", _
    ScreenTip:="", _
   TextToDisplay:="Doc2.doc"
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

That worked great!

I did have to change the .InsertAfter(Chr(11))
to .InsertAfter(vbCrLf). It kept inserting the number 11.

Thanks for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top