Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

use the shell command to open a word file in My Documents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Margaret Bartley - 23 Nov 2005 03:35 GMT
This works:
   strCommand = "winword.exe C:\test.doc /mDoThis"
   varMyDoc = Shell(strCommand, vbMaximizedFocus)

When I execute this, I get a file not found error:
   strCommand = "winword.exe C:\Documents and Settings\mbartley\test.doc"
   varMyDoc = Shell(strCommand, vbMaximizedFocus)

Same thing for this:
    strCommand = "winword.exe 'C:\Documents and
Settings\mbartley\test.doc'"
    varMyDoc = Shell(strCommand, vbMaximizedFocus)

My assumption is it's the spaces in the directory that are flummoxing the
compiler.

I'm modifying someone else's complicated code.  This is a utility procedure,
and I don't want to change the overall logic by implementing a different
approach, I want to keep the Shell command logic, but don't know how to
implement it when I've got a space in the file name.

Any help?
Jay Freedman - 23 Nov 2005 05:15 GMT
>This works:
>    strCommand = "winword.exe C:\test.doc /mDoThis"
[quoted text clipped - 18 lines]
>
>Any help?

You need to embed double quotes in the string to surround the path:

 Dim qt As String
 qt = Chr$(34)
 strCommand = "winword.exe " & qt & _
       "C:\Documents and Settings\mbartley\test.doc" & qt

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
Thomas Lindberg - 23 Nov 2005 06:11 GMT
>>This works:
>>    strCommand = "winword.exe C:\test.doc /mDoThis"
[quoted text clipped - 33 lines]
> Email cannot be acknowledged; please post all follow-ups to the
> newsgroup so all may benefit.

The need for double quotes in macros pops up now and then but I have not yet
found a so simple way to realize it!

Thanks, Jay!

Thomas
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.