谢谢楼上,但你的不能实现预期功能,chylhr兄已帮我解决,请参阅以下代码: Private Sub CommandButton1_Click() Dim CNN, RS1 Dim strSQL1$, strFind$, strHyperlink$, strPath$ Dim myRange As Range, TF As Boolean, i As Integer, Exist As Boolean Dim Lc As Integer, Count As Integer Set CNN = CreateObject("Adodb.Connection") Set RS1 = CreateObject("Adodb.Recordset") strPath = ActiveDocument.Path & "\TOC.mdb" CNN.Provider = "Microsoft.Jet.OLEDB.4.0" CNN.Open "Data Source =" & strPath & ";Jet OLEDB:Database Password=" & "" strSQL1 = "select * from TOC" RS1.Open strSQL1, CNN, 1, 3 For i = 1 To RS1.RecordCount Set myRange = ActiveDocument.Content strFind = RS1.Fields("TLFno") strHyperlink = RS1.Fields("LinkAddress") Count = 0 myRange.Find.ClearFormatting Do While myRange.Find.Execute(findtext:=strFind, Wrap:=wdFindStop, Forward:=True) Count = Count + 1 ActiveDocument.Hyperlinks.Add Anchor:=myRange, Address:=strHyperlink, _ SubAddress:="", ScreenTip:="", TextToDisplay:=strFind myRange.SetRange Start:=myRange.End + Len(strFind) + 1, End:=ActiveDocument.Content.End '估计是Word查找的Bug,Start取值在myRange.End与myRange.End + Len(strFind)之间竟然会查找到以查找范围前面的那个strFind。 '另外,在End的取值中使用动态的ActiveDocument.Content.End要比静态的lngEnd更合适 Loop MsgBox strFind & ":" & CStr(Count) RS1.movenext Next RS1.Close End Sub |