vb.net word bold

FCapo
FCapo used Ask the Experts™
on
Hi,

I'm using an app in vb.net to send text to word using bookmarks. Is there a way to tell word to make a specific word  BOLD, such as below :

docWord.Bookmarks.Item("ContactTxt").Range.Text = ContactTxt.Text & vbCr & "<b>" & ClientNameTxt.Text & "</b>" & vbCr & AddresseTxt.Text & vbCr & VilleTxt.Text & " " & PostalTxt.Text
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
Hi,

if you have already <b> and </b>

you coud use
    With docWord.Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Replacement.Font.Bold = True
        .Text = "\<b\>(*)\</b\>"
        .Replacement.Text = "\1"
        .Forward = True
        .Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
        .Execute Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll
    End With

Open in new window

Regards
GrahamSkanRetired
Top Expert 2012
Commented:
This is fromthe classic VBA model:

Dim rng As Word.Range

'set contact text in bold
Set rng = docWord.Bookmarks.Item("ContactTxt").Range '(set is redundant in .net, so must be omitted, i.e. rng = docWord.Bookmarks.Item("ContactTxt").Range)
rng.Text = ContactTxt.Text & vbCr
rng.Bold = True

'append extra unbolded text
rng.Collapse wdCollapseEnd
rng.Bold = False
rng.Text = AddresseTxt.Text & vbCr & VilleTxt.Text & " " & PostalTxt.Text

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial