Shelling Wordpad

D

DavidJ

Hi all

Wonder if anyone can help...

I am shelling wordpad in vba code but wordpad doesn't seem to like
spaces in the filename.

My code...

Private Sub cmdNotepad_Click()

Dim varX As Variant
Dim strMyDoc As String

strMyDoc = "C:\Documents and Settings\Doc\My Documents\Nis2.rtf"
'strMyDoc = "C:\setup.log"

varX = Shell("C:\Program Files\Windows NT\Accessories\wordpad.exe"
& " " & strMyDoc, vbMaximizedFocus)

End Sub

When run with setup.log it works fine but when using Nis2.rtf wordpad
complains it can't find the file, and show the filename up to the first
space in "Document and Settings"

Any suggestions would be appreciated
 
G

Graham Mayor

Change strMyDoc to

strMyDoc = """C:\Documents and Settings\Doc\My Documents\Nis2.rtf"""


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

Roger Hunt

Hi all

Wonder if anyone can help...

I am shelling wordpad in vba code but wordpad doesn't seem to like
spaces in the filename.

My code...

Private Sub cmdNotepad_Click()

Dim varX As Variant
Dim strMyDoc As String

strMyDoc = "C:\Documents and Settings\Doc\My Documents\Nis2.rtf"
'strMyDoc = "C:\setup.log"

varX = Shell("C:\Program Files\Windows NT\Accessories\wordpad.exe"
& " " & strMyDoc, vbMaximizedFocus)

End Sub

When run with setup.log it works fine but when using Nis2.rtf wordpad
complains it can't find the file, and show the filename up to the first
space in "Document and Settings"

Any suggestions would be appreciated
Shot in the dark - perhaps Wordpad uses the MSDOS path name, internally.
So I wonder if this would work :
strMyDoc = "C:\Docume~1\doc\Mydocu~1\Nis2.rtf"
 
D

DavidJ

Roger said:
Shot in the dark - perhaps Wordpad uses the MSDOS path name, internally.
So I wonder if this would work :
strMyDoc = "C:\Docume~1\doc\Mydocu~1\Nis2.rtf"

Spot on Roger, while both solutions worked as hard coded path/filename
when obtained from forms using the MSGOS path name worked perfectly.

Thanks for the assistance guys.
 
D

DavidJ

DavidJ said:
Spot on Roger, while both solutions worked as hard coded path/filename
when obtained from forms using the MSGOS path name worked perfectly.

Thanks for the assistance guys.

Whoops, typo, I did mean MSDOS of course.
 
R

Roger Hunt

Spot on Roger, while both solutions worked as hard coded path/filename
when obtained from forms using the MSGOS path name worked perfectly.
Nice one! But I think Graham's solution is better practise - I was
always taught (our VB tutor beat it into us with a thick manual) that
the clearer the code, if possible, the better, and sprinkled with
appropriate comments.

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top