|
有两个文本文件1.txt 2.txt
现在要将2.txt文件中的内容追加到1.txt的最后,而不是覆盖掉1.txt的内容,
如1.txt 内容为:
I love excelhome.
I am a freshman.
2.txt的内容为:
Can you do me a favor?
Thanks in advance!
想要的结果是1.Txt 的内容为
I love excelhome.
I am a freshman.
Can you do me a favor?
Thanks in advance!
请问用VBA 代码如何实现?
谢谢!
已解决,代码如下,如理解错误,欢迎批评指正,谢谢!
Sub test()
Dim fso, f, a
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.opentextfile("c:\2.txt", 1)
a = f.readall
f.Close
Set f = fso.opentextfile("c:\1.txt", 8)
f.writeline a
f.Close
End Sub
说明:
Set f = fso.opentextfile("c:\1.txt", 8)中的数字表示的意义:
1表示该文件只读
2表示该文件可写入内容,但写入的内容覆盖以前的内容
8表示该文件可写入内容,且写入的内容追加到后面不覆盖一存在的内容!
[ 本帖最后由 welky 于 2009-5-26 23:00 编辑 ] |
|