问题描述
我是VBA的新手并且无法完成此任务。我已经搜索过但仍然没有回答。
I'm new to VBA and haven't been able to accomplish this. I've searched and still have no answer.
我需要一个宏来搜索文档中的字符串,然后更改该字符串中单个单词的格式。我曾尝试录制宏来执行此操作,但如果录制器正在运行,则不允许我从搜索字符串中选择单个单词。
所以,这也不起作用。具体来说,我需要找到每次出现的事件
I need a macro that will search a document for a string and then change the formatting on a single word in that string. I have tried to record a macro to do that but if the recorder is running, it won't allow me to select a single word from the search string. So, that didn't work either. Specifically, I need to find every occurrence of
状态:打开
并将"打开"的格式更改为红色和粗体。
and change the formatting of 'Open' to red and bold.
感谢您的帮助!
推荐答案
Sub FormatText()
Selection.HomeKey单位:= wdStory
使用Selection.Find
.ClearFormatting
.Text ="状态:打开< b $ b .Replacement.ClearFormatting
Do While .Execute
Selection.MoveStart单位:= wdWord
使用Selection.Font
.Bold = True
.ColorIndex = wdRed
结束与$
Selection.Collapse Direction:= wdCollapseEnd
循环
结束于$
结束子
Sub FormatText()
Selection.HomeKey Unit:=wdStory
With Selection.Find
.ClearFormatting
.Text = "Status: Open"
.Replacement.ClearFormatting
Do While .Execute
Selection.MoveStart Unit:=wdWord
With Selection.Font
.Bold = True
.ColorIndex = wdRed
End With
Selection.Collapse Direction:=wdCollapseEnd
Loop
End With
End Sub
这篇关于更改搜索字符串中单个单词的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!