Sub OpenCloseArray()
Dim MyFile As String
Dim Arr(400) As String
Dim count As Integer
MyFile = Dir("D:\" & "*.txt") '遍历D盘根目录下所有文本文件
count = count + 1
Arr(count) = MyFile
Do While MyFile <> ""
MyFile = Dir
If MyFile = "" Then
Exit Do
End If
count = count + 1
Arr(count) = MyFile '将文件的名字存在数组中
Loop
For i = 1 To count
FileName = "D:\" & Arr(i)
If FileName = False Then Exit Sub
Set FSO = CreateObject("Scripting.FileSystemObject")
Set f = FSO.opentextfile(FileName)
s = Replace(f.readall, "”", Chr(34)) '这里是要替换的文字
s = Replace(s, "“", Chr(34))
s = Replace(s, "‘", "'")
s = Replace(s, "’", "'")
s = Replace(s, "—", "-")
f.Close
Set r = FSO.opentextfile(FileName, 2, True)
r.write s
Next
End Sub