PC Review


Reply
Thread Tools Rate Thread

Bold words in document

 
 
m stroup
Guest
Posts: n/a
 
      15th Oct 2008
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.
f:\doc.doc")

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

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

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

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

End Function
--
Teach me to fish! Thanks for the help.
Pax, M
 
Reply With Quote
 
 
 
 
Alex Dybenko
Guest
Posts: n/a
 
      16th Oct 2008
Hi,
try to switch off "check proofing as you type" option in word, sometimes it
helps.
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)
http://accessblog.net
http://www.PointLtd.com


"m stroup" <(E-Mail Removed)> wrote in message
news:3E883E04-F5E9-47AA-8139-(E-Mail Removed)...
> 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.
> f:\doc.doc")
>
> Set objWord = New Word.Application
> Set objDoc = objWord.Documents.Open(strDoc)
> Set objRg = objDoc.Range
> Set db = CurrentDb()
> Set rs = db.OpenRecordset("tblWords", dbOpenDynaset)
>
> rs.MoveFirst
> Do While Not rs.EOF
> Set objRg = objDoc.Range
> With objRg.Find
> .Text = " " & rs![Word] & " "
> While .Execute
> objRg.Font.Bold = wdToggle
> Wend
> End With
> Set objRg = objRg.Document.Range
> With objRg.Find
> .Text = " " & rs![Word] & "."
> While .Execute
> objRg.Font.Bold = wdToggle
> Wend
> End With
> rs.MoveNext
> Loop
>
> objWord.Documents(strDoc).Close SaveChanges:=wdSaveChanges
> objWord.Quit
>
> Set objRg = Nothing
> Set objDoc = Nothing
> Set objWord = Nothing
> Set rs = Nothing
> Set db = Nothing
>
> End Function
> --
> Teach me to fish! Thanks for the help.
> Pax, M


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I bold key words in Access cwenui Microsoft Access Reports 1 3rd Jun 2009 09:24 PM
When I apply bold to a word the whole document goes bold - ? mikisdad Microsoft Word Document Management 2 25th Jul 2008 04:32 AM
Bold words in a MsgBox Paolo Microsoft Access 8 23rd Jan 2005 08:13 PM
Re: Bold words in a MsgBox Минин Павел Microsoft Access 0 23rd Jan 2005 04:46 PM
Bold Specific Words MarkA Microsoft Access VBA Modules 1 7th Aug 2003 12:15 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:00 PM.