
Running a file from a .VBS script
You can use the Run method of Windows Scripting Host's Shell class. An
example follows. Notice the Chr(34) functions surrounding the file name to
add double-quotes around the file name in case the file name contains
spaces.
On Error Resume Next
Dim objWSH
Set objWSH = CreateObject("WScript.Shell")
objWSH.Run Chr(34) & "C:\Documents and Settings\eric\My Documents\doc1.doc"
& Chr(34)
If Err.number <> 0 Then
msgbox "Problem: " & Err.Description
Else
msgbox "All good"
End IF
Set objWSH = Nothing
MCSD, Brainbench MVP for Visual Basic
http://www.brainbench.com
Quote:
> I couldn't find the best newsgroup to post this question
> in, so sorry if this is off-topic....
> What I'd like to do is to have a command in a .VBS script
> run a file (similiar to if I went to Start-Run, typed the
> file name, and hit enter)
> For example, I'd like to have the .VBS file run
> C:\docs\agenda.doc (which would fire up microsoft word
> with this document open).
> Any ideas? Thanks.
> -Clark