替换所有txt文件中的所有标签

时间:2018-11-25 18:19:43

标签: vba replace

我有一个包含多个文本文件的文件夹,我需要用空格替换每个文件中的所有选项卡。

使用VBA最简单的方法是什么?

预先感谢 杰夫

1 个答案:

答案 0 :(得分:0)

Sub TabsToSpace()
    Dim f As String, pth As String

    pth = "your_directory_path\"

    f = Dir(pth & "*.txt")
    While f <> ""
        Documents.Open FileName:=pth & f

        With Selection.Find
            .Text = "^t"
            .Replacement.Text = " "
            .Forward = True
            .Wrap = wdFindContinue
            .Execute Replace:=wdReplaceAll
        End With

        ActiveDocument.Save
        ActiveDocument.Close

        f = Dir
    Wend
End Sub