如何解决从 Word 中的字符中删除粗体格式
Sub rep_test()
Dim TempS As String
TempS = Replace_chars("]","]")
End Sub
Function Replace_chars(search_txt As String,replace_txt As String)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = search_txt
.Replacement.Text = replace_txt
.Replacement.Font.Bold = False
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll,Format:=False
End Function
文本示例:
Aaa [BBB] CC [DDD]
知道为什么吗?
解决方法
试试:
Sub rep_test()
Call Replace_chars("]")
End Sub
Sub Replace_chars(search_txt As String)
Application.ScreenUpdating = False
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = search_txt
.Replacement.Text = "^&"
.Font.Bold = True
.Replacement.Font.Bold = False
.Format = True
.Forward = True
.MatchWildcards = False
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
End With
Application.ScreenUpdating = True
End Sub
,
如果要删除格式,正确的方法是应用字符样式“默认段落字体”。这将重置格式以匹配基础段落样式。它还具有您不需要知道需要删除/应用什么格式的优点。
Sub FindAndResetFormatting(search_txt As String)
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = search_txt
.Replacement.Style = ActiveDocument.Styles(wdStyleDefaultParagraphFont)
.Forward = True
.Wrap = wdFindStop
.Format = True
.Execute Replace:=wdReplaceAll
End With
End Sub
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。