0

Error System can't find the file specified

strCline = Document.getElementById("head").innerHtml
msgbox strCline
strCline = replace(strCline, " ",Chr(32))
oShell.run strCline
Set oShell = Nothing

Above code produces error because it can't read file name properly. It's all because of space characters in file name. After reading, i found chr(32) would replace space character but it won't. How do I make it take space character.

Edit:
My final code looked like this which worked. I made mistake while creating object.

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
2
  • 3
    You'll have to double quote file specs containing spaces. Post (typical) content of strCline. Commented Jun 24, 2013 at 20:01
  • I didn't get you. Are you suggesting 1. "strLine" 2. strCline = replace(strCline, " "," ") or another one? strCline may have values like: "first text" or "second text file". I don't why spaces get dropped while oShell.Run get executes. Commented Jun 24, 2013 at 20:08

1 Answer 1

3

The shell splits a command line into parameters using blank(s) for a delimiter. If you want to send text file specifications to .Run to display them automagically in the default editor, you must double quote the (logically) single parameter. This demo code:

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

will output:

"C:\Documents and Settings\eh\tmp.txt" => -2147024894
""C:\Documents and Settings\eh\tmp.txt"" => 0

and open only one Notepad.

See here for some context.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.