Reputation: 1431
I am having trouble bolding part of a paragraph in MS WORD
.
I am building a document paragraph by paragraph. In only one of those I want to bold only one number. The number may occur more than once in the document but should be bolded only once, in this specific paragraph.
Example:
My first paragraph.
My second paragraph.
My number is 123.
I access paragraphs with the following code:
Dim paragraphN As Integer
paragraphN = 3
ActiveDocument.Sections(1).Range.Paragraphs(paragraphN).Range
I don`t know how to specify only a part of this specific paragraph. I tried:
ActiveDocument.Sections(1).Range.Paragraphs(paragraphN).Range(Start:=14, End:=17).Font.Bold = True
ActiveDocument.Sections(1).Range.Paragraphs(paragraphN).Range.Characters(Start:=14, End:=17).Font.Bold = True
ActiveDocument.Sections(1).Range.Paragraphs(paragraphN).Characters(Start:=14, End:=17).Range.Font.Bold = True
ActiveDocument.Sections(1).Range.Paragraphs(paragraphN).Characters.Range(Start:=14, End:=17).Font.Bold = True
ActiveDocument.Sections(1).Range.Paragraphs(paragraphN).Range(14,17).Font.Bold = True
All failed. The problem seems pretty straightforward but I am out of ideas...
Upvotes: 0
Views: 2187
Reputation: 1183
The accepted answer didn't work for me because I couldn't do a Range(x, y) without an error. This worked for me however... doc.Paragraphs(paragraphIndex).Range.Sentences(1).Font.Bold = True
Upvotes: 0
Reputation: 11755
I was able to get it to work using a slightly different method:
ActiveDocument.Range(ActiveDocument.Paragraphs(1).Range.Characters(5).Start, _
ActiveDocument.Paragraphs(1).Range.Characters(10).End).Font.Bold = True
You can adjust the paragraph numbers and character numbers with your variables.
Upvotes: 1