如何使用VBA在Microsoft Word中隐藏字符?

如何使用VBA在Microsoft Word中隐藏字符?,vba,ms-word,hide,Vba,Ms Word,Hide,我想在Microsoft Word中隐藏字符,更具体地说是在某些字符之间隐藏文本 例如,如果我得到这个: ::00-58-96:: Hello there ::00-58-97:: This is a test ::00-58-98:: Nothing else ::00-58-99:: Good bye ! 我想将文本隐藏在 :: :: 结果是 Hello there This is a test Nothing else Good bye ! Again this

我想在Microsoft Word中隐藏字符,更具体地说是在某些字符之间隐藏文本

例如,如果我得到这个:

::00-58-96:: Hello there
::00-58-97:: This is a test
::00-58-98:: Nothing else
::00-58-99:: Good bye !

我想将文本隐藏在

::        ::

结果是

Hello there
This is a test
Nothing else
Good bye !

Again this
Is a
Test

另一个例子是

==this:example== Again this
==this:example== Is a
==this:example== Test

结果是

Hello there
This is a test
Nothing else
Good bye !

Again this
Is a
Test

我不知道我是否很好地暴露了我的问题

我已经尝试过这样做(一些其他人帮助我),但这会替换文本,而不是隐藏它:

Sub l()
'
'
'
    ActiveDocument.Range.Select '

With Selection.Find
     .MatchWildcards = True
     .Text = "::*::"
     .Replacement.Text = ""
     .Execute Replace:=wdReplaceAll, Forward:=True, _
     Wrap:=wdFindContinue
End With


End Sub


更新:

Private Sub SelFind()


    Dim Rng As Range
    Dim Fnd As Boolean

G:
    Set Rng = ActiveDocument.Range


    With Rng.Find
        .ClearFormatting
        .MatchWildcards = True
        .Execute FindText:="::*::", Forward:=True, _
                 Format:=False, Wrap:=wdFindStop
        Fnd = .Found
    End With

    If Fnd = True Then
        With Rng
            .MoveStart wdWord, 0
            .Select
            With .Font
                .Hidden = True
            End With
        End With
        GoTo G

    Else:

    MsgBox "All done"

    End If
End Sub
Word仍在崩溃/只是隐藏了我文档的第一行,我只修改了一行,如下所示:

Private Sub SelFind()


    Dim Rng As Range
    Dim Fnd As Boolean

G:
    Set Rng = ActiveDocument.Range


    With Rng.Find
        .ClearFormatting
        .MatchWildcards = True
        .Execute FindText:=";;*;;*;;", Forward:=True, _
                 Format:=False, Wrap:=wdFindStop
        Fnd = .Found
    End With

    If Fnd = True Then
        With Rng
            .MoveStart wdWord, 0
            .Select
            With .Font
                .Hidden = True
            End With
        End With
        GoTo G

    Else:

    MsgBox "All done"

    End If
End Sub


试试这个:

Private Sub SelFind()


    Dim Rng As Range
    Dim Fnd As Boolean

G:
    Set Rng = ActiveDocument.Range


    With Rng.Find
        .ClearFormatting
        .MatchWildcards = True
        .Execute FindText:="::*::", Forward:=True, _
                 Format:=False, Wrap:=wdFindStop
        Fnd = .Found
    End With

    If Fnd = True Then
        With Rng
            .MoveStart wdWord, 0
            .Select
            With .Font
                .Hidden = True
            End With
        End With
        GoTo G

    Else:

    MsgBox "All done"

    End If
End Sub

从中获得帮助

是否有一种方法可以在Word中隐藏文本而不使用VBA,手动从工具栏隐藏文本?有一种方法:当您转到>字体,然后在“效果”部分,box Hidden将执行此操作,但当您获得非常大的文件时,您会浪费大量时间执行此操作,这就是我拼命搜索宏的原因。为找到的文本设置
.Font.Hidden=True
。@Satanas。。现在就用答案中的代码。。。非常好用。哇,谢谢你,这通常应该像你说的那样非常好用,但唯一的问题是我的Word在宏执行后崩溃了,我会搜索可能的问题,但谢谢你,我应该能够从现在起修改此代码:)试着用F8一步一步地运行,这样,您就可以知道它崩溃的原因以及经过多少次搜索。我知道,宏仅应用于第一行:)即使GoTo发送到宏的开头以再次迭代,情况也不应该如此……正如我尝试和测试的那样。
;;00:00:08;;00:00:10;;代表人,但不代表其姓名;;00:00:11;;00:00:13;;白兰地病是一种腐败;;00:00:14;;00:00:15;;Nam libero Temporate,兼首席执行官;;00:00:15;;00:00:17;;(二)因犯罪而犯罪的时间;;00:00:18;;00:00:20;;非轮回桑科。青藤;;00:00:22;;00:00:23;;你能试试这个吗?这是我来源的原文。