-2

需要这样的代码......应该隐藏两个标签之间存在的数据......为此,我首先在文档中搜索标签,然后用注册的符号(®)替换该标签并获得那样的范围。我需要一个代码而不用替换标签

Sub Test()
Dim i As Long
i = 0
Dim myWord As String
myWord = "®"
TargetList = Array("</hidden>")
With ActiveDocument.Content.Find
     .Text = "</hidden>"
     .Replacement.Text = myWord
     .Wrap = wdFindContinue
     .Execute Replace:=wdReplaceAll
End With 
  Counter = 1
Set Range = ActiveDocument.Range
Selection.HomeKey Unit:=wdStory
With Selection.Find
    .Forward = True
    .Wrap = wdFindStop
    .Text = "<hidden>"
While .Execute
    Counter = Counter + 1
Wend
End With
For i = 0 To Counter
Set Range = ActiveDocument.Range
Selection.HomeKey Unit:=wdStory
With Selection.Find
    .Forward = True
    .Wrap = wdFindStop
    .Text = "<hidden>"
If .Execute(Forward:=True) = True Then
With Selection.Range
Selection.MoveEndUntil Cset:="®", Count:=wdForward
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Hidden = True
End With
End If
End With
Next i
End Sub
4

1 回答 1

3

您可以使用通配符使用简单的 Word 查找和替换来实现此目的:

With Selection.Find
    .ClearFormatting
    .ClearAllFuzzyOptions

    .text = "[<]hidden[>](*)[<]/hidden[>]"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True

    .Replacement.text = ""
    .Replacement.ClearFormatting

    .Replacement.Font.Hidden = True

    .Execute Replace:=wdReplaceAll
End With

如果您还想删除标签,请使用以下替换文本:

    .Replacement.text = "\1"
于 2013-05-15T12:17:44.290 回答