Dj_soo 发表于 2013-12-10 10:17
直接另存为txt格式应该是一个比较方便的方法,但是不知道效率如何.
Sub test()
' ActiveWorkbook.SaveAs Filename:="c:\abc.txt", FileFormat:=xlCurrentPlatformText '间隔较宽,不知怎样规定的
' ActiveWorkbook.SaveAs Filename:="c:\abc.txt", FileFormat:=xlTextMac
' ActiveWorkbook.SaveAs Filename:="c:\abc.txt", FileFormat:=xlTextMSDOS
' ActiveWorkbook.SaveAs Filename:="c:\abc.txt", FileFormat:=xlTextPrinter '有的无间隔
' ActiveWorkbook.SaveAs Filename:="c:\abc.txt", FileFormat:=xlTextWindows
' ActiveWorkbook.SaveAs Filename:="c:\abc.txt", FileFormat:=xlUnicodeText '间隔较宽,不知怎样规定的
'
'其它几种都是 运行时错误1004:方法'SaveAs'作用于对象'_Workbook'时失败
End Sub
难道只有ActiveWorkbook.SaveAs 才能更快?
难道以下办法都只是花拳绣腿,处理数据量一大,就不如ActiveWorkbook.SaveAs?
1) Print # 语句 Sub txt_1()
Open "d:\2.txt" For Output As #1
Print #1, "你好!"
Close #1
End Sub
2) Put 语句 Sub txt_2()
Open "d:\2.txt" For Binary As #1
Put #1, , "你还好!"
Close #1
End Sub
3) Write # 语句 Sub txt_3()
Open "d:\2.txt" For Output As #1
Write #1, "你总好!"
Close #1
End Sub
4) WriteLine 方法 Sub txt_4()
Dim fs, a, arr
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("d:\2.txt", True)
a.WriteLine ("你还好!")
a.Close
End Sub
5) Write 方法 Sub txt_5()
Dim fs, a, arr
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("d:\2.txt", True)
a.Write ("老是你好!")
a.Close
End Sub |