Link to home
Start Free TrialLog in
Avatar of AWestEng
AWestEngFlag for Sweden

asked on

VBScript: Add hyperlink in table cell, Ms Word 2007

Hi how do I add a hyperlink in a table cell? (MS Word 2007)

I like the www.test.com to become a hyperlink.
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objRange = objDoc.Range
 
Set objRange = objDoc.Range
objRange.Collapse wdCollapseEnd
Set objTable = objDoc.Tables.Add(objRange, 2, 2)
 
objTable.Borders.Enable = true
 
With objTable.Cell(2, 2).Range 
	.Font.Name = "Verdana"
	.Font.Size = 8
	.Font.Bold = false
	.Text = _
		"Address for visitors:" & Chr(11) & _
		"xxxxxxxxxx" & Chr(11) & _
		"yyyyyyyyyy" & Chr(11) & _
		"<a href='Web:www.test.com'>test.com/a>"
End With

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Shift-3
Shift-3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AWestEng

ASKER

almost perfect, I need the huperlink just under text other text like this

Xxxxxx
 yyyyyy
 www.test.com

now it look like this

Xxxxxx
 yyyyyy

 www.test.com
found it

Set objCell = objTable.Cell(2, 2)
Set objCellRange = objCell.Range
objCell.Select
objSelection.Font.Name = "Verdana"
objSelection.Font.Size = 8
objSelection.Font.Bold = false
objSelection.TypeText _
    "Xxxxxx:" & Chr(11) & _
    "yyyyyy" & Chr(11) & _
    "Web: "
objSelection.InsertAfter Text = "yyyyyy"
objSelection.Font.Name = "Verdana"
objSelection.Font.Size = 8
objSelection.Font.Bold = true
    Set objLink = objSelection.Hyperlinks.Add(objSelection.Range, "http://www.test.com", , , "www.test.com")