Board logo

標題: [發問] 如何寫入/讀取.txt檔資料 [打印本頁]

作者: acdx    時間: 2017-11-11 23:05     標題: 如何寫入/讀取.txt檔資料

我希望在表單開啟時能檢查是否有pathFile.txt存在,
若無->在我的文件夾中create一個pathFile.txt並寫入"mypath"
若有->讀取pathFile.txt中最後一列資料
卻出現錯誤 請問該如何修正?
Private Sub UserForm_Initialize()
Dim workpath As String
Dim rLine As String
Dim a As Object
Set myText = CreateObject("Scripting.FileSystemObject")
Set myText = myText.OpenTextFile(Filename:="pathFile.txt") ', IOMode:=ForAppending, Create:=True)
    a = myText.READALL
    Do While InStr(a, vbCrLf) Or InStr(a, vbLf & vbLf)
        a = Replace(a, vbCrLf, vbLf)   
        a = Replace(a, vbLf & vbLf, vbLf)
    Loop
    If Mid(a, Len(a)) = vbLf Then a = Mid(a, 1, Len(a) - 1)
    a = Split(a, vbLf)
myText.Close

End Sub




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)