Bold words in document


m stroup

I have a table of words in an access db. I want to check word documents
against this list and highlight any words in the doc that match. This
procedure works but it takes way too long. Any suggestions?

Function Boldwords()

Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objRg As Range
Dim strDoc As String
Dim db As Database
Dim rs As Recordset

strDoc = InputBox("Enter the path and file name of document. i.e.

Set objWord = New Word.Application
Set objDoc = objWord.Documents.Open(strDoc)
Set objRg = objDoc.Range
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblWords", dbOpenDynaset)

Do While Not rs.EOF
Set objRg = objDoc.Range
With objRg.Find
.Text = " " & rs![Word] & " "
While .Execute
objRg.Font.Bold = wdToggle
End With
Set objRg = objRg.Document.Range
With objRg.Find
.Text = " " & rs![Word] & "."
While .Execute
objRg.Font.Bold = wdToggle
End With

objWord.Documents(strDoc).Close SaveChanges:=wdSaveChanges

Set objRg = Nothing
Set objDoc = Nothing
Set objWord = Nothing
Set rs = Nothing
Set db = Nothing

End Function

Alex Dybenko

try to switch off "check proofing as you type" option in word, sometimes it
If this is a plain text in word - then I suggest to copy it to a string var,
do everything in access, marking bold words as #word#, and then apply
formatting in word in one step

Best regards,
Alex Dybenko (MVP)

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question