I want to add many hyperlinks via VBA for my MS-Word file, for 1st paragraph the hyperlink is "./index/1.doc", 2nd paragraph is "./index/2.doc", and so on. The simpilfied procedure is 1)select one paragraph 2)add hyperlink, just as the following code says. However, the VBA code gives every paragraph same hyperlink which only should be for the last paragraph. So, is there any way to deselect in VBA to perform this case? Thanks
btw, the VBA can be tested on any MS-Word file with more than 1 paragraphs.
Sub addHypertext()
For countParagraph = 1 To ActiveDocument.Paragraphs.Count
Selection.Collapse Direction:=wdCollapseEnd
set para = ActiveDocument.Paragraphs(countParagraph)
para.Select
Set paraStyle = para.Style
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, \
Address:="./index/" & countParagraph & ".doc"
Rem this does not work
Rem Selection.Range.Style = paraStyle
Rem this does not work
Selection.Style = paraStyle
Rem this does not work too
Rem para.Style = paraStyle
Rem this produces "run-time error"
Rem para.Range.Style = "text"
Next
End Sub