【发布时间】:2018-11-12 15:00:12
【问题描述】:
我创建了一个函数,用于在一系列文档中查找文本,并在找到时对文本应用阴影。 我运行代码如下,但它会找到整个文档文本并应用阴影。
如何使该功能起作用?谢谢!
Public Function myFun_findTxt2addShading( _
str_findTxt As String, _
range_myRange, _
str_repTxt As String, _
str_ShadingColor As String) As Boolean
Dim boolean_checkFound As Boolean
boolean_checkFound = False
range_myRange.Select
With Selection
.Find.ClearFormatting
.Find.Replacement.ClearFormatting
.Find.Text = str_findTxt
.Find.Replacement.Text = str_repTxt
.Find.Forward = True
.Find.Replacement.Font.ColorIndex = str_RepFontColor
.Find.Wrap = wdFindStop
Do While .Find.Execute
Selection.Shading.Texture = wdTextureNone
Selection.Shading.ForegroundPatternColor = wdColorAutomatic
Selection.Shading.BackgroundPatternColor = str_ShadingColor
boolean_check = True
Loop
.Find.Format = False
.Find.MatchCase = False
.Find.MatchWholeWord = False
.Find.MatchByte = False
.Find.MatchWildcards = False
.Find.MatchSoundsLike = False
.Find.MatchAllWordForms = False
End With
findTxt_Shading = boolean_checkFound
End Function
Sub test()
With Selection
.HomeKey Unit:=wdStory
.Find.Execute findText:="bookmark1", Forward:=True, Wrap:=wdFindStop
.MoveDown Unit:=wdLine
.HomeKey Unit:=wdLine
ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="sybStart"
.Find.Execute findText:="bookmark2", Forward:=True, Wrap:=wdFindStop
.HomeKey Unit:=wdLine
ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="sybEnd"
End With
Set sybRange = ActiveDocument.Range
sybRange.Start = sybRange.Bookmarks("sybStart").Range.End
sybRange.End = sybRange.Bookmarks("sybEnd").Range.Start
a = myFun_findTxt2addShading("pp", sybRange, "pp", wdColorYellow)
End Sub
【问题讨论】:
-
你给它的
Selection.Range是什么?它是否代表您要使用的特定Selection?请edit您的帖子填写空白,目前没有足够的信息来制作一个好的minimal reproducible example。