错误系统无法找到指定的文件
strCline = Document.getElementById("head").innerHtml
msgbox strCline
strCline = replace(strCline, " ",Chr(32))
oShell.run strCline
Set oShell = Nothing
上面的代码会产生错误,因为它无法正确读取文件名。这都是因为文件名中的空格字符。阅读之后,我发现chr(32)将取代空间角色,但事实并非如此。如何让它占据空间特征。
修改
我的最终代码看起来像是有效的。我在创建对象时犯了错误。
Sub funEdit
set oShell=createobject("Wscript.shell")
strCline = Document.getElementById("head").innerHtml
msgbox strCline
strCline = replace(strCline, " ",Chr(32))
oShell.run strCline
Set oShell = Nothing
End Sub
答案 0 :(得分:3)
shell使用空格将命令行拆分为参数,用于分隔符。如果要将文本文件规范发送到.Run以在默认编辑器中自动显示它们,则必须双引号(逻辑)单个参数。这个演示代码:
Option Explicit
Dim sFSpec : sFSpec = "C:\Documents and Settings\eh\tmp.txt"
Dim sCmd : sCmd = sFSpec
Dim oWSH : Set oWSH = CreateObject("WScript.Shell")
On Error Resume Next
oWSH.Run sCmd
WScript.Echo qq(sCmd), "=>", Err.Number, Err.Description
Err.Clear
sCmd = qq(sFSpec)
oWSH.Run sCmd
WScript.Echo qq(sCmd), "=>", Err.Number, Err.Description
On Error GoTo 0
Function qq(s)
qq = """" & s & """"
End Function
将输出:
"C:\Documents and Settings\eh\tmp.txt" => -2147024894
""C:\Documents and Settings\eh\tmp.txt"" => 0
并仅打开一个记事本。
有关某些情况,请参阅here。