时间太忙,KONGGS又不愿意出手,只好草草地修改了一下,供参考了:
Sub Inserthyperlink() Dim i As Integer, j As Integer, bknameB As String, bknameA As String Dim myRange As Range, myTable As Table Application.ScreenUpdating = False With ActiveDocument .Fields.Unlink j = 0 For i = 2 To .Tables.Count Set myTable = .Tables(i) If InStr(myTable.Cell(1, 1).Range, "媒体名称:") <> 0 Then j = j + 1 bknameB = "B" & VBA.Format(j, "000") .Bookmarks.Add Name:=bknameB, Range:=.Range(myTable.Cell(4, 2).Range.Start, myTable.Cell(4, 2).Range.Start) End If Next i
j = 0 Set myTable = .Tables(1) For i = 2 To myTable.Rows.Count j = j + 1 bknameA = "A" & VBA.Format(j, "000") bknameB = "B" & VBA.Format(j, "000") Set myRange = .Range(myTable.Cell(i, 6).Range.Start, myTable.Cell(i, 6).Range.End - 1) .Bookmarks.Add Name:=bknameA, Range:=myRange .Hyperlinks.Add Anchor:=myRange, Address:="", SubAddress:=bknameB Next i
j = 0 Set myRange = .Content '定义一个RANGE对象,为主文档文字部分 NextFind: With myRange.Find '查找 .ClearFormatting .Font.Name = "黑体" .Format = True .Text = "返回" Do While .Execute j = j + 1 '计数 bknameA = "A" & VBA.Format(j, "000") '定义一个书签名 '添加一个超级链接 ActiveDocument.Hyperlinks.Add Anchor:=myRange, Address:="", SubAddress:=bknameA myRange.SetRange myRange.Paragraphs(1).Range.End, ActiveDocument.Content.End GoTo NextFind Loop End With End With Application.ScreenUpdating = True End Sub
|