[英]Select unbolded text & change its colour (of a selected paragraph)- MS Word VBA Macro
注意:我不想對整個文檔文本執行此操作,只是對我選擇的段落/塊文本執行此操作)
圖片展示了我想做的事情:
我嘗試創建以下宏 - 但由於某種原因,它使所有文本(粗體和非粗體)變為藍色
Sub MakeUnboldedTextBlue()
'
' MakeUnboldedTextBlue Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Font.Bold = False
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Font.Color = 15773696
End Sub
更新:我還想從'氰化'中排除子彈符號(如果可能)
例如: 未被氰化的子彈符號示例
您查看所選文本中的每個字符,如果它不是粗體,則將其着色:
Option Explicit
Sub CyanizeNonBoldInSelection()
Dim oRange As range
Dim oChar As range
Dim oListFormat As ListFormat
Application.UndoRecord.StartCustomRecord "CyanizeNonBoldInSelection"
Set oRange = Selection.range
For Each oChar In oRange.Characters
If oChar.Bold = False Then
oChar.Font.ColorIndex = wdTurquoise
If oChar.ListParagraphs.Count > 0 Then
Set oListFormat = oChar.ListParagraphs(1).range.ListFormat
oListFormat.ListTemplate.ListLevels(oListFormat.ListLevelNumber).Font.ColorIndex = wdTurquoise
End If
End If
Next oChar
Application.UndoRecord.EndCustomRecord
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.