【发布时间】:2021-06-11 23:11:41
【问题描述】:
我正在编写一个宏,它应该将所有找到的值打印到一个文本文件中。到目前为止,我得到了 find 宏,找不到可以获取每个找到结果的每个值的部分。
Sub ReplaceAndWrite()
Dim TextFile As Integer
Dim FilePath As String
Dim FileName As String
FileName = ActiveDocument.Name
FilePath = ActiveDocument.Path & "\" & FileName & ".txt"
TextFile = FreeFile
Open FiledPath For Output As TextFile
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "(#VL-*>) <[! ,^13]@#"
.ReplacementText = "\1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
With .Replacement
.ClearFormatting
.Font.Bold = True
.Font.ColorIndex = wdBlue
.Font.Underline = True
.Font.AllCaps = True
End With
.MatchCase = False
.Execute Replace:=wdReplaceAll
End With
End With
Close TextFile
End Sub
如何将找到的结果写入文本文件? 是否可以遍历所有结果并将它们的值写入文本文件? 有没有更好的方法来完成这样的任务?
【问题讨论】: