求助下面代码VBA如何实现对文本文件删除、替换及保存!
发布网友
发布时间:2022-05-24 18:26
我来回答
共1个回答
热心网友
时间:2023-10-25 02:48
在全文各处做替换,请参看:
Private Sub Loadtxt()
Dim strData(1 To 10000) As String
TotalLines = 0
strFileName = Application.GetOpenFilename("CSV Files (*.txt), *.txt", , "Open TXT File", , False)
On Error GoTo LEND
Open strFileName For Input As #1
While Not EOF(1)
Line Input #1, textline
TotalLines = TotalLines + 1
strData(TotalLines) = Replace(textline, "aaa", "ACB", 1, 1)
Wend
Close #1
Open strFileName For Output As #1
For i = 1 To TotalLines
Print #1, strData(i)
Next i
Close #1
LEND:
End Sub追问谢谢FLIPZD,用你上面这种方式只能是替换一次文本就要重新将文件写入,我可能有很多次的替换,这样效率太低,我已经找到解决方法了,谢谢!