View Single Post
 
Old 01-11-2024, 01:41 AM
WordVB WordVB is offline Windows 11 Office 2016
Novice
 
Join Date: Jan 2024
Location: Ireland
Posts: 12
WordVB is on a distinguished road
Default Bold certain parts of bookmarks text code help

Hi All,

I am looking for some ideas please. This is the first time I am using VB so still am very fresh here. I am working on a simple word document, where the front page is used to check boxes and based on true false values it inserts texts in bookmark fields further down the document. Managed to get all with the help of this Forum but got stuck with one step. The text I am inserting looks like below:

"Title

First line"



What I want to do is to make word "Title" bold and leave the rest non-bold.

Option Explicit
Dim oRng As Range
Dim oBM As Bookmark


Private Sub CheckBox1_Click()
If Me.CheckBox1.Value = True Then
Set oRng = ActiveDocument.Bookmarks("Text1").Range
oRng.Text = "Title" & Chr(10) & "First line"
ActiveDocument.Bookmarks.Add "Text1", oRng
With oRng.Font
.Bold = True
End With
Else: Set oRng = ActiveDocument.Bookmarks("Text1").Range
oRng.Text = "Blank"
ActiveDocument.Bookmarks.Add "Text1", oRng
With oRng.Font
.Bold = False
End With
End If
End Sub

It could do something with selecting the range but I am unsure how.

Any thoughts would be greatly appreciated.
Reply With Quote