Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with Word documents

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi people,

Nedd help with some stuff. I am trying to get my VB program to generate a microsoft winword report with some formatting like bold, underlining, etc.

However, it seems that once I unbold something, the whole document gets unbold, the same goes for the different type s of formatting.

With oWord

.ActiveDocument.Range.InsertParagraph
.ActiveDocument.Range.Font.Bold = True
.ActiveDocument.Range.InsertAfter "This line is bold, very bold"

.ActiveDocument.Range.InsertParagraphAfter

.ActiveDocument.Range.Font.Bold = False
.ActiveDocument.Range.InsertAfter "This line isn't bold, isn't very bold"


End With

Thanks in Advance.
Brendon
 
The best way to do this is to record a macro while you type some of the report. You will be able to see the sequence of events that you need to bold and unbold as you type.
 
I found your problem, what you are doing is applying bold to the whole document, before you apply bold to the doc you need to collpse the range, do:

With oWord

.ActiveDocument.Range.InsertParagraph
.ActiveDocument.Range.Font.Bold = True
.ActiveDocument.Range.InsertAfter "This line is bold, very bold"

.ActiveDocument.Range.InsertParagraphAfter

Set rng = .ActiveDocument.Range
rng.Collapse wdCollapseEnd

rng.Font.Bold = False
rng.InsertAfter "This line isn't bold, isn't very bold"

End With

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top