VB如何打开一个文本文件

2025-03-01 19:20:07
推荐回答(3个)
回答1:

1、获取文本文件路径
2、通过流的方式打开文本文件
示例:
Dim MyString
Private Sub Command1_Click() ’按钮事件
Open App.Path + "\Myfile.txt" For Input As #1 '打开文本文件,读取。
Do While Not EOF(1) '是否没到文件末尾
Input #1, MyString '读取文件内容
Loop
Close #1
End Sub

回答2:

open "d:\1.txt" for binary as #1
dim txtstr as string
get #1,,txtstr
txtstr=replace(txtsrt,"123","456")
put #1,,txtstr
close #1

'我就不开VB了

回答3:

如果生成的可执行文件和WORD文件不在同一文件夹,代码应该是怎样的我已经给一文本 一按钮 text里输入文档得完整路径 Private Declare Function