可以实现写入,txt或是word,但是,我需要的是,我写入的内容,能够自由的保存,(可以选择保存在哪个盘符,可以对保存的文件命名),这该怎么实现请各位高手指点,本人是个新手,学的东西很多,请帮助,谢谢

解决方案 »

  1.   

    '新建一个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
      

  2.   

    Set fs = CreateObject("Scripting.FileSystemObject")
        Set a = fs.CreateTextFile("c:\testfile.txt", True)
        a.WriteLine ("This is a test.")
        a.Close用这段程序,我可以实现写入数据到txt中,但是,我需要的是,写入的时候,能够弹出对话框,能够选择保存的盘符,还有自己命名。就像常见的保存文件一样
    该怎么实现?
      

  3.   


    请教各位大哥
    小弟使用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
    程序运行后出现如下提示:

    编译错误:
    用户定义类型未定义
    请问是什么原因?
      

  4.   

    编译错误:
    用户定义类型未定义
    请问是什么原因?需要先引用"microsoft  scripting  runtime"
      

  5.   

    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 实现
      

  6.   

    请教各位大哥
    小弟使用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
    程序运行后出现如下提示:

    编译错误:
    用户定义类型未定义请问是什么原因?
      

  7.   

    不是告你了么,需要先引用"microsoft  scripting  runtime"
      

  8.   

    怎么引用“microsoft scripting runtime”
      

  9.   

    把代码作如下修改即可,不用做引用
    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