vb中shell函数如何保存一个文本文件

来源:百度知道 编辑:UC知道 时间:2024/05/28 06:50:00
我想过shell保存一个txt文本,

语法应该是怎样的阿?
Sub Runtimer()
Application.OnTime Now + TimeValue("00:00:10"), "SaveIt"
End Sub

Public Sub SaveIt()
Dim str As String
str = "notepad " + Sheet3.Cells(3, 4) 'Sheet3.Cells(3, 4)为读取的外部txt文件
Shell str, vbNormalFocus
End If
End Sub

我如果执行上面这个 不能得到保存的结果么

应该用open方法吧……
shell只可能通过命令行调用其他程序才能创建文件吧

不能
首先过程Runtimer内的Application是什么?
且过程Runtimer没有传递任何参数给SaveIt函数
再者str = "notepad " + Sheet3.Cells(3, 4)
Sheet3.Cells(3, 4)必须是一个文件不存在的绝对路径(如:g:\a.txt)如果存在就是用记事本打开
如果是相对路径的话,记事本会保存文件到C:\Documents and Settings\<USERNAME>\下
<USERNAME>是你的帐户名
所以str = "notepad " + Sheet3.Cells(3, 4) 'Sheet3.Cells(3, 4)为读取的外部txt文件
Shell str, vbNormalFocus
只是创建一个空的TXT文件

shell是用来启动外部程序的。。。

文件通用读、写、追加函数

Sub Appdoc(ByVal docpath As String, ByVal txt As String)'追加记录函数
Open docpath For Append As #1
Print #1, txt
Close #1
End Sub

Public Function openfile(ByVal filepath As String) As String'读入文件函数
Dim s As String
Open filepath For Input As #1
While Not EOF(1)
Line Input #1, sline
s = s & sline & vbCrLf
Wend
Close #1
openfile = s
End Function