假如數據結構不是這樣的話,方法也會變化的。
請明示
張誌晨
Dim txtName As String
Function getFileName(dlg As Object) As String
'添加 commondialog1
'添加 file1, 可設為不可見 也就是只當作數組
On Error GoTo err
With dlg
.DialogTitle = "請指定文件夾"
.Filter = "文本文件(*.txt)|*.txt"
.ShowOpen
getFileName = .FileName
End With
Exit Function
err:
MsgBox "您沒有選擇文件或者文件夾中沒有txt文件"
End Function
'寫
Sub wirteTxt(namePath As String, txt As String)
Open namePath For Output As #1
Print #1, txt
Close #1
End Sub
'讀
Function lineRead(namePath As String) As String
'多行數據
Dim strLine As String
Dim strBox As String
Open namePath For Input As #1
Do Until EOF(1)
Line Input #1, strLine
strBox = strBox + strLine + vbCrLf
Loop
Text1(0).Text = strBox
Text1(1).Text = Replace(strBox, "1234", "5678")
Close #1
End Function
Private Sub Command1_Click()
txtName = getFileName(CommonDialog1)
lineRead txtName
End Sub
Private Sub File1_Click() '這只是修改壹個文件,妳可以用循環修改文件夾下所有的txt文件
lineRead File1.List(ListIndex)
wirteTxt txtName, Text1(1).Text
End Sub