编辑宏代码
EXCEL选择"视图">"宏">"查看宏"
创建宏
在弹出的对话框中输入以下代码
Sub BoldSpecificTextOnly()
Dim cell As Range
Dim searchTexts As Variant
Dim i As Integer
Dim foundCount As Long
Dim startPos As Integer
Dim textLen As Integer
' 设置要查找并加粗的多个文本
searchTexts = Array("现在状态:", "情况描述:", "帮扶措施:")
foundCount = 0
' 遍历工作表中的每个单元格
For Each cell In ActiveSheet.UsedRange
If Len(cell.Value) > 0 Then
For i = LBound(searchTexts) To UBound(searchTexts)
startPos = InStr(1, cell.Value, searchTexts(i), vbTextCompare)
' 如果找到关键词
If startPos > 0 Then
textLen = Len(searchTexts(i))
' 只加粗关键词部分
cell.Characters(Start:=startPos, Length:=textLen).Font.Bold = True
foundCount = foundCount + 1
End If
Next i
End If
Next cell
MsgBox "已将 " & foundCount & " 处关键词加粗!"
End Sub
执行宏
EXCEL选择"视图">"宏"
选择刚刚创建的宏,点击"执行"