Shell Command

GrahamK

Registered User.
Local time
Today, 10:53
Joined
Aug 5, 2008
Messages
25
Hello All,

I'm having trouble running a piece of VBA code - centering around the shell command. The code is below:

Code:
Private Sub cmdOpenFile_Click()
On Error GoTo Errhand
 
Dim strfilepath As String
 
strfilepath = Path.Value

Debug.Print strfilepath
Shell strfilepath, vbMaximizedFocus
 
Errhand:
If Err.Number = 20 Then
    Resume Next
ElseIf Err.Number <> 0 Then
    MsgBox (Err.Number & " " & Err.Description)
    Exit Sub
End If
End Sub

The file path in the debug.print is showing fine, but it is generating the error "5 Invalid Procedure Call or Arguement"

Can anyone shed any light on why this is happening, or, an alternative to the code above?

Many Thanks
Graham
 
Does the path contain any spaces or other special characters?
 
Yes Mailman,

Path as below:
H:\1Glasgow%20&%20the%20West%20Highlands.pdf

VMT
Graham
 
Just an update - I've changed the file name to

H:\1GlasgowtheWestHighlands.pdf

and I'm still getting the same error

Many Thanks
Graham
 
I think shell is one of those things you HAVE to call as a function... try:
dim r as integer
r = shell (strfilepath, vbMaximizedFocus)
 
Thanks Mailman,

But still to no avail...

Graham
 
what does

shell (path) mean?

you have to shell to a program

so it would have to be something like

shell (acrobat & " " & filename)

---------
now whether you need the full path for acrobat, or whether windows will know this for you, i am not sure. I am also not sure how to build in the file name as the argument for the shell command.
 
Howzit

I found this somewhere on my travles over the net - not sure where or who wrote it.

This opens (the ones I have tested anyway) Word, Excel. Access, pdf., by passing the full doc path the sub - in my case held in a text box relevant to the record I am in.

Code:
Public Sub OpenDocument(DocPath As String)
Dim A As Long
A = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & DocPath, vbMaximizedFocus)
End Sub
 
THanks Dave,

I declared the whole path to the application executable as a variable and now works fine! Next head ache now.....!

Many Thanks
Graham
 

Users who are viewing this thread

Back
Top Bottom