Filename with spaces in the 'Shell' function

  • Thread starter Thread starter suy
  • Start date Start date
S

suy

Guest
I know this question has been posted before : how to use

shell("c:\winword.exe " & filename)

if filename contains spaces (e.g. filename = name & " " & firstname & " " DOB.

I read the suggestion to use the DOS name, but this is unknown, and I can't change the filenames.

How can I open those word-files with code ?

Thanks.
 
I remember trying to solve this one a while back; it seems that the SHELL command can be incredibly obtuse at times.

You can find out the short name that belongs to a given long file name with this bit of code, then use that, but I can't help feeling there's a better way...
 
You mean like this:

Dim strFirst As String
Dim strSecond As String
Dim strThird As String

strFirst = "C:\Program" & " " & "Files\"
strSecond = "Snapshot" & " " & "Viewer\"
strThird = "snapview.exe"

Call Shell(strFirst & strSecond & strThird, 1)

or this:

strFirst = "C:\Program" & " " & "Files\"
strSecond = "Snapshot" & " " & "Viewer\"
strThird = "My Program.exe"

Either way that should work. Post back if I missed the point entirely.

EDIT - The more I read your question the more I think that I did miss the point of your post.

[This message has been edited by BukHix (edited 12-13-2001).]
 
If you file name contains spaces it needs to be between double quotations when you pass it over to WORD.

shell("winword.exe ""c:\test file.doc""",vbMaximizedFocus)

Hope this works for you

CT
 
Thanks for your help, I'll try it.
I 've found also that there is no problem wit GetObject, so I can use it instead of Shell.
 

Users who are viewing this thread

Back
Top Bottom