使用 VBA for word 选择文本并使其加粗 [英] Using VBA for word to select text and make it bold
本文介绍了使用 VBA for word 选择文本并使其加粗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我每周都会制作几页的 Word 文档.我从 PDF 复制文本并将其粘贴到 Word 文档中,然后格式化粘贴的文本.
I make a several page word document every week. I copy text from a PDF and paste it into a word document, I then format the text that I pasted.
这需要很长时间,我想自动化它.
This takes a long time and i would like to automate it.
我需要一个宏或一些代码来选择特定文本,然后将该文本设为粗体.我需要加粗的特定文本就是我所说的废旧代码.
I need a macro or some code to select specific text, then make that text bold. The specific text i need to bold is what i call a scrap code.
有 60 种不同的代码.例如FIPS"或LILL".
There are 60 different codes. For example "FIPS", or "LILL".
推荐答案
是这样的:
Sub A()
'
' a Macro
'
'
Dim A(3) As String
A(1) = "code1"
A(2) = "code2"
A(3) = "code3"
For i = 1 To 3
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Replacement.Font.Bold = True
.Execute FindText:=A(i), ReplaceWith:=A(i), Format:=True, _
Replace:=wdReplaceAll
End With
Next i
End Sub
HTH!
编辑
将美元金额转换为粗体
Sub a()
'
' a Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Bold = True
With Selection.Find
.Text = "$([0-9.,]{1,})"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
这篇关于使用 VBA for word 选择文本并使其加粗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文