谢谢gues1688了,不过现在有两个问题:
1.插入的书签b系列书签并没有插入到找到的"SGM News Clipping from China"上,而是都插入到了光标当前位置。
2.目录中加入标签和超链接我都做好了,关键是每篇剪报第一行中给那个“top”加超链接我还不会。
目前完成的代码如下:
1)给目录加书签:
Sub bookmarkA() Application.ScreenUpdating = False Dim mystr As String, i As Integer, k As Integer, bkmark As Bookmark, m As String Set mydoc1 = ActiveDocument totalnumber = mydoc1.Bookmarks.Count For i = totalnumber To 1 Step -1 mydoc1.Bookmarks(i).Delete Next i k = 1 For Each Row In mydoc1.Tables(1).Rows m = k - 1 mydoc1.Bookmarks.Add Name:="a" & m, Range:=mydoc1.Tables(1).Rows(k).Cells(1) k = k + 1 Next Application.ScreenUpdating = True End Sub 2)给目录加超链接:
Sub hyA() Application.ScreenUpdating = False Dim mystr As String, i As Integer, k As Integer, m As String, x As Integer Set mydoc1 = ActiveDocument Set mytable = mydoc1.Tables(1) i = mytable.Rows.Count 'MsgBox i For k = 2 To i x = k - 1 mystr = mydoc1.Range(mytable.Cell(k, 5).Range.Start, mytable.Cell(k, 5).Range.End - 1) 'MsgBox mystr mydoc1.Range(mytable.Cell(k, 5).Range.Start, mytable.Cell(k, 5).Range.End - 1).Select With Selection ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", _ SubAddress:="b" & x, ScreenTip:="", TextToDisplay:=mystr End With Next k Application.ScreenUpdating = True End Sub
上面两个不管怎么说还是能运行的,下面两个就是问题所在了:
3)给每篇剪报加书签,但是书签都没有加到正确的位置上:
Sub bookmarkb() Application.ScreenUpdating = False Dim k As Integer, m As String, findchar As String, mystr As String findchar = "SGM News Clipping from China" k = 1 With ActiveDocument.Content.find Do While .Execute(findtext:=findchar) = True m = String(3 - Len(CStr(k)), "0") & CStr(k) Selection.find.Execute ActiveDocument.Bookmarks.Add Name:="b" & m k = k + 1 Loop End With Application.ScreenUpdating = True End Sub
4)给每篇剪报第一行的“top”加超链接,遇到两个问题:
a.找到每页第一行的“top”而不要其它位置的“top”
b.和第3)段代码的问题一样,插入的超链接都在当前光标处,而不是在找到的“top”处。 |