- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
6#
發表於 2013-11-12 21:08
| 只看該作者
本帖最後由 GBKEE 於 2013-11-13 07:57 編輯
回復 5# acdx
試試看- Option Explicit
- Private Sub CommandButton1_Click() 'Save
- Dim txtFile As Variant, i As Integer, fs As Object
- txtFile = Application.GetOpenFilename("文字文件,*.txt;*.txt", , "指令:Save", , False)
- If TypeName(txtFile) = "Boolean" Then
- MsgBox "No file was selected."
- Else
- Set fs = CreateObject("Scripting.FileSystemObject")
- Set fs = fs.OpenTextFile(txtFile, 2, 0)
- ' 參數 : 2
- ' 1 開啟一個唯讀檔案,無法對此檔案進行寫入。
- ' 2 開啟一個用於寫入的檔案。如果和此檔案同名的檔案已存在,則覆蓋以前內容。
- ' 8 開啟一個檔案並寫輸出至檔案的尾部。
- For i = 1 To 5
- fs.WriteLine Controls("TEXTBOX" & i)
- Next
- fs.Close
- End If
- End Sub
- Private Sub CommandButton2_Click() 'LOAD
- Dim txtFile As Variant, i As Integer, fs As Object
- txtFile = Application.GetOpenFilename("文字文件,*.txt;*.txt", , "指令:Load", , False)
- If TypeName(txtFile) = "Boolean" Then
- MsgBox "No file was selected."
- Else
- Set fs = CreateObject("Scripting.FileSystemObject")
- Set fs = fs.OpenTextFile(txtFile, 1, 0)
- For i = 1 To 5
- Controls("TEXTBOX" & i) = fs.READLine
- Next
- fs.Close
- End If
- End Sub
複製代碼 |
|