Sub BoldAndColorLinesStartingWithTripleHash()
Dim doc As Document
Dim para As Paragraph
Dim lineText As String
Dim rng As Range
Dim pos As Integer
' Set the document
Set doc = ActiveDocument
' Loop through each paragraph in the document
For Each para In doc.Paragraphs
lineText = para.Range.Text
pos = InStr(lineText, "###")
' If the paragraph starts with '###', format the entire paragraph
If pos = 1 Then
Set rng = para.Range
rng.Font.Bold = True
rng.Font.Color = wdColorBrown
rng.Font.Size = 11
End If
Next para
End Sub
Tuesday, December 24, 2024
VBA Word - Text formatting if text begins with some text
The following VBA code formats the text which begins with hash:
VBA Word - Format Text of word document based on the properties of text
The following VBA code finds text with properties such as color, size and name in Word document and change their color etc.
Sub HighlightAndColorText()
Dim doc As Document
Dim rng As Range
Set doc = ActiveDocument
Set rng = doc.Content
With rng.Find
.ClearFormatting
.Font.Color = RGB(0, 0, 255) ' Blue font color
.Font.Size = 10 ' Font size
.Font.Name = "Century Gothic" ' Font style
Do While .Execute(Forward:=True, Format:=True) = True
' Set the background color to yellow
rng.Shading.BackgroundPatternColor = wdColorBlack
' Change the font color to white
rng.Font.Color = RGB(255, 255, 255)
' Move the search range to the end of the current found text
rng.Collapse Direction:=wdCollapseEnd
Loop
End With
End Sub
Subscribe to:
Posts (Atom)
Hot Topics
-
The @page directive The @page directive in ASP.NET Core Razor Pages is crucial because it designates a Razor file as a Razor Page, allowin...
-
Objectives To provide detailed information about ListBox Types of ListBox Using ListBox in VBA applications Please read the post till end...
-
VBA TypeOf is followed by a reference type variable or expression which returns an object data type. This object type is compared with anot...