如何使用 VBA 隐藏 Microsoft Word 中的字符?
How can I hide characters in Microsoft Word using VBA?
我想在 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 !
另一个例子是
==this:example== Again this
==this:example== Is a
==this:example== Test
结果会是
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
更新:
Word 仍然crashing/just 隐藏了我文档的第一行,我只修改了一行如下:
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
得到了帮助Answer
我想在 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 !
另一个例子是
==this:example== Again this
==this:example== Is a
==this:example== Test
结果会是
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
更新:
Word 仍然crashing/just 隐藏了我文档的第一行,我只修改了一行如下:
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
得到了帮助Answer