Date: Thu, 26 Jul 2007 03:57:46 -0000
Reply-To: Stanley Wei <medpower@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Stanley Wei <medpower@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: How could I add multi-hyperlinks automatically in a word
In-Reply-To: <8AD8F86B3312F24CB432CEDDA71889F203EF7A64@ex06.GHCMASTER.GHC.ORG>
Content-Type: text/plain; charset="us-ascii"
Thanks Roy,
I wrote the following word VBA code in. I have stored the items to be
find
and hyperlink address in an access database, the database and table
name are both called TOC (fileds include TLFNO and LINKADDRESS), could
anyone help me find the problem of the following codes? it just work
for the first found item, I need to operate for all of items met with
the requirements, thanks!
Stanley
Private Sub CommandButton3_Click()
Dim CNN, RS1
Dim strSQL1$, strFind$
Dim myRange As Range
Set CNN = CreateObject("Adodb.Connection")
Set RS1 = CreateObject("Adodb.Recordset")
strPath = ThisDocument.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
Application.ScreenUpdating = False
For i = 1 To RS1.RecordCount
strFind = RS1.Fields("TLFNO")
Set myRange = ActiveDocument.Content
With myRange.Find
.ClearFormatting
.Format = True
.Font.Color = wdColorBlue
.Text = RS1.Fields("TLFNO")
If .Execute(findtext:=strFind) = True Then
myRange.Select
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range,
Address:=RS1.Fields("LinkAddress"), _
SubAddress:="", ScreenTip:="",
TextToDisplay:=RS1.Fields("TLFNO")
End If
End With
RS1.movenext
Next
Application.ScreenUpdating = True
RS1.Close
End Sub
|