Please Help!? Shell Command

G

Guest

Good Morning all,
I am trying to open different Word Documens in a certain program (Wordview)
using the Shell command. I can get the program to run but it is not opening
the required documents. Here is what I have:

Dim strShell As String

strShell = """C:\Program Files\Microsoft Office\OFFICE11\Wordview.exe"" &_
""\\Mercury\Users\AshleyS\Trim Line\" & Me.Work_Station & "\"
&_ Me.Work_Instruction
Shell strShell, vbMaximizedFocus

Where Work_Station and Work Instruction are fields in the form.
Your help would be much appreciated! Cheers.
 
A

Albert D.Kallal

Why not use:

application.FollowHyperlink "path to doc name"

The above works for excel, word, pdf, or whatever (it is as if you just
cliked on it...).

So, you code would be somting like:

Dim strShell As String

strShell = "\\Mercury\Users\AshleyS\Trim Line\" & Me.Work_Station &
Me.Work_Instruction

application.FollowHyperlink strShell

So, with the above, you don't care if the user have word, or whatever, you
just need a path to the actual document name
 
G

Guest

Yes but I would like to Open the document using Wordview so that it is non
editable. Follow Hyperlink does work but this is not what I require.
Thanks
 
D

Douglas J Steele

Is that an actual copy-and-paste of your code? Your line continuation
characters aren't correct: there needs to be a space before the _.

As well, you appear not to have a space between the path to the executable,
and the path to the file, and your quotes aren't correct.

Try:

strShell = """C:\Program Files\Microsoft Office\OFFICE11\Wordview.exe"" " &
_
"""\\Mercury\Users\AshleyS\Trim Line\" & Me.Work_Station & _
"\" & Me.Work_Instruction & """"
Shell strShell, vbMaximizedFocus

If you're finding the doubling and tripling of quotes confusing, you could
try:

strShell = Chr$(34) & "C:\Program Files\Microsoft
Office\OFFICE11\Wordview.exe" & _
Chr$(34) & " " & Chr$(34) & "\\Mercury\Users\AshleyS\Trim
Line\" & _
Me.Work_Station & "\" & Me.Work_Instruction & Chr$(34)

since Chr$(34) = "
 
G

Guest

Still not working Dougie!! Program is opening up but not document, no error
messages nothing.
Any suggestions??
Cheers
--
Regards

Ashley Smart


Douglas J Steele said:
Is that an actual copy-and-paste of your code? Your line continuation
characters aren't correct: there needs to be a space before the _.

As well, you appear not to have a space between the path to the executable,
and the path to the file, and your quotes aren't correct.

Try:

strShell = """C:\Program Files\Microsoft Office\OFFICE11\Wordview.exe"" " &
_
"""\\Mercury\Users\AshleyS\Trim Line\" & Me.Work_Station & _
"\" & Me.Work_Instruction & """"
Shell strShell, vbMaximizedFocus

If you're finding the doubling and tripling of quotes confusing, you could
try:

strShell = Chr$(34) & "C:\Program Files\Microsoft
Office\OFFICE11\Wordview.exe" & _
Chr$(34) & " " & Chr$(34) & "\\Mercury\Users\AshleyS\Trim
Line\" & _
Me.Work_Station & "\" & Me.Work_Instruction & Chr$(34)

since Chr$(34) = "
 
D

Douglas J Steele

And you're sure that """\\Mercury\Users\AshleyS\Trim Line\" &
Me.Work_Station & "\" & Me.Work_Instruction & """" is generating a path to
an existing file?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


A. Smart said:
Still not working Dougie!! Program is opening up but not document, no error
messages nothing.
Any suggestions??
Cheers
 
G

Guest

Positive! Thats the exsact same code I used when I was opening the file
normally as a hyperlink.
Only problem it might be is the hyphens, but VB hasn't any problems with it.
Cheers
 
D

Douglas J Steele

Try printing the content of strShell to the immediate window and
copy-and-paste it here, just to see whether it looks good. Don't know what
you'll be able to do to prevent word-wrap (which could hide the presence or
lack of spaces)
 
G

Guest

strShell = Chr$(34) & "C:\Program Files\Microsoft
Office\OFFICE11\Wordview.exe" & _
Chr$(34) & " " & Chr$(34) & "\\Mercury\Users\AshleyS\Trim
Line\" & _
Me.Work_Station & "\" & Me.Work_Instruction & Chr$(34)
 
D

Douglas J Steele

You misunderstood.

I mean that in your code, you should put

Debug.Print strShell

after you assign it its value, but before you issue call to the Shell
function.

Then, when you run your code, go to the Immediate Window (Ctrl-G), copy
what's printed there and paste it here.
 
G

Guest

Sorry Doug, amateurs hey! Here u go:

"C:\Program Files\Microsoft Office\OFFICE11\Wordview.exe"
"\\Mercury\Users\AshleyS\Trim Line\GU010 Body Fit 1\Body
Protection.doc#Y:\AshleyS\Trim Line\GU010 Body Fit 1\Body Protection.doc#"

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