首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VBA >

vba写txt资料

2013-03-17 
vba写txt文件用vba往txt文件中写东西,怎么样能从空白行开始写?不覆盖原来txt文件中存在的东西vba[解决办法

vba写txt文件
用vba往txt文件中写东西,怎么样能从空白行开始写?不覆盖原来txt文件中存在的东西 vba
[解决办法]

Sub test1111()
    Dim fso, sFile
    Dim str, filepath, filename As String
    Dim linecount As Integer
    filepath = "d:"
    filename = "1.txt"
    Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateFalse = 0 'ForAppending从文件末尾追加
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(filepath & filename) = True Then
        Set sFile = fso.OpenTextFile(filepath & filename, ForAppending, TristateFalse)
        sFile.Write ("Hello world!")
        'sFile.Writeline ("Hello world!")
        sFile.Close
    End If
    Set fso = Nothing
    Set sFile = Nothing
End Sub

热点排行