vb 导入excel

来源:百度知道 编辑:UC知道 时间:2024/05/04 17:33:23
我制作了1个vb的小程序,希望能将程序上选择的内容直接导入指定的excel中,这个功能已经实现,但有个问题是,我希望每次打开这个程序,都可以把最后的结果导入到同一个excel中,不覆盖原有信息,如何实现,请教各位了,谢谢
您的回答我没有看明白啊,请说的详细一些,谢谢!我的程序每次导入的信息并不多,可能只有1条(不是1个text,还有combo里的信息,选择好点击save按钮生成excel),但我的目的是希望每次关闭程序再打开存储的信息能在同1个excel里以“行”累加,不覆盖原来的信息,是关闭程序再后打开程序,可以记住我上次存储的“行”,谢谢大家

Set fso = CreateObject("Scripting.FileSystemObject")

Set logFile =fso.OpenTextFile("D:\runtime.xls", 8, True)

logFile.WriteLine "aaaaaa"

logFile.Close

D:\runtime.xls换成你指定的excel文件名;
logFile.WriteLine "aaaaaa"这句话就是将aaaaaa写入到你指定的excel文件里。

OpenTextFile方法里的第二个参数:
1 Open a file for reading only. You can't write to this file.
2 Open a file for writing.
8 Open a file and write to the end of the file.

可以在程序前端添加一段代码,如:
do
if cells(i,1)=""then exit do
i=i+1
loop
i1=i
下面程序的起始行改为i1