文本框editbox中的内容写入txt,或word ?怎么实现?

fargood 2005-09-15 04:55:28
可以实现写入,txt或是word,但是,我需要的是,我写入的内容,能够自由的保存,(可以选择保存在哪个盘符,可以对保存的文件命名),这该怎么实现

请各位高手指点,本人是个新手,学的东西很多,请帮助,谢谢

...全文
234 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
VBDN 2005-09-17
  • 打赏
  • 举报
回复
把代码作如下修改即可,不用做引用
Private Sub Command1_Click()
Dim fso, txtfile, fil, ts, s
Set fso = CreateObject("scripting.filesystemobject")
Set txtfile = fso.createtextfile("c:\testfile.txt", True)
txtfile.Close
MsgBox "正在写入文件"
Set fil = fso.getfile("c:\testfile.txt")
Set ts = fil.openastextstream(2)
ts.write "hello world"
ts.Close
Set ts = fil.openastextstream(1)
s = ts.readline
MsgBox s
ts.Close
End Sub
liuxicheng 2005-09-17
  • 打赏
  • 举报
回复
谢谢大哥
liuxicheng 2005-09-16
  • 打赏
  • 举报
回复
怎么引用“microsoft scripting runtime”
northwolves 2005-09-15
  • 打赏
  • 举报
回复
不是告你了么,需要先引用"microsoft scripting runtime"
liuxicheng 2005-09-15
  • 打赏
  • 举报
回复
请教各位大哥
小弟使用file system objects 读取文件,要从一个文本文件中读取数据,程序如下:
Private Sub Command1_Click()
Dim fso As New filesystemobject, txtfile, fil As File, ts As textstream
Set txtfile = fso.createtextfile("c:\testfile.txt", True)
MsgBox "正在写入文件"
Set fil = fso.getfile("c:\testfile.txt")
Set ts = fil.openastextstream(forwriting)
ts.write "hello world"
ts.Close
Set ts = fil.openastextstream(forreading)
s = ts.readline
MsgBox s
ts.Close
End Sub
程序运行后出现如下提示:

编译错误:
用户定义类型未定义

请问是什么原因?
northwolves 2005-09-15
  • 打赏
  • 举报
回复
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\testfile.txt", True)
a.WriteLine ("This is a test.")
a.Close

用这段程序,我可以实现写入数据到txt中,但是,我需要的是,写入的时候,能够弹出对话框,能够选择保存的盘符,还有自己命名。就像常见的保存文件一样
该怎么实现?

Private Sub Command1_Click()
CommonDialog1.InitDir = "d:\"
CommonDialog1.FileName = "123.txt"
CommonDialog1.Filter = "文本文件(*.txt)"
CommonDialog1.ShowSave
End Sub


----------------------
简单点,可以用一个COMMONDIOLOGBOX 实现
northwolves 2005-09-15
  • 打赏
  • 举报
回复
编译错误:
用户定义类型未定义
请问是什么原因?

需要先引用"microsoft scripting runtime"
liuxicheng 2005-09-15
  • 打赏
  • 举报
回复

请教各位大哥
小弟使用file system objects 读取文件,要从一个文本文件中读取数据,程序如下:
Private Sub Command1_Click()
Dim fso As New filesystemobject, txtfile, fil As File, ts As textstream
Set txtfile = fso.createtextfile("c:\testfile.txt", True)
MsgBox "正在写入文件"
Set fil = fso.getfile("c:\testfile.txt")
Set ts = fil.openastextstream(forwriting)
ts.write "hello world"
ts.Close
Set ts = fil.openastextstream(forreading)
s = ts.readline
MsgBox s
ts.Close
End Sub
程序运行后出现如下提示:

编译错误:
用户定义类型未定义
请问是什么原因?
fargood 2005-09-15
  • 打赏
  • 举报
回复
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\testfile.txt", True)
a.WriteLine ("This is a test.")
a.Close

用这段程序,我可以实现写入数据到txt中,但是,我需要的是,写入的时候,能够弹出对话框,能够选择保存的盘符,还有自己命名。就像常见的保存文件一样
该怎么实现?

shanlisong 2005-09-15
  • 打赏
  • 举报
回复
'新建一个txt文件
Dim objCreateTxtFile As Object
Dim a
Set objCreateTxtFile = CreateObject("Scripting.FileSystemObject")
Set a = objCreateTxtFile.CreateTextFile(文件路径, TXT名称, True)
a.Close
Set objCreateTxtFile = Nothing
' 写入txt文件
Open 刚才创建的TXT名称全路径 For Binary As #1
Put #1, , 要写的内容
Close #1

1,066

社区成员

发帖
与我相关
我的任务
社区描述
VB 资源
社区管理员
  • 资源
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧