Word VBA Help

D

Dana King

I need to write a utility (in .net) that will iterate though a word document
and extract words with bold formatting. These will go into a database. No
problem except I'm not sure about writing the VBA to find bold words in a
document.

Has anyone done this before? Could you post some sample code?

Thanks in advance.
 
D

Dave Lett

Hi,

This will get you started:

Dim sBold As String
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Text = ""
.Font.Bold = True
Do While .Execute
sBold = sBold & Replace(Trim(Selection.Text), Chr(13), "") &
vbCrLf
Loop
End With
End With
Debug.Print sBold

I use the Replace function to remove any boldface hard returns.

HTH,
Dave
 

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

Top