Shell function and Run time error 5 (1 Viewer)

mor

Registered User.
Local time
Today, 20:19
Joined
Jun 28, 2013
Messages
56
Hi there,

I'm looking to use the shell function to dynamically call different pdfs that are in a directory. However I'm getting run time error 5 "Invalid procedure or call argument".

Here is the code (very basic I know)..


Private Sub Liste_Documentation_DblClick(Cancel As Integer)

Dim PathName As String
PathName = Me.Liste_Documentation.Column(2)

' Debug.Print PathName

Shell PathName


End Sub


A typical filepath name is as follows..
S:\Vente\Vendeurs\Marc\CRM\DOCS\Diligences KYC - LABFT - V 2013 04 23.pdf


Any help would be greatly appreciated.

Many thanks,
MOR
 

pr2-eugin

Super Moderator
Local time
Today, 19:19
Joined
Nov 30, 2011
Messages
8,494
Hello mor, I think Shell returns a Number.. So try assigning it to a Long variable..
Code:
Dim retVar As Long
retVar = Shell(PathName)
 

mor

Registered User.
Local time
Today, 20:19
Joined
Jun 28, 2013
Messages
56
Hi Paul,

Thanks very much. Apologies if I've used the code wrong but have done this...

Private Sub Liste_Documentation_DblClick(Cancel As Integer)

Dim PathName As String
PathName = Me.Liste_Documentation.Column(2)

Debug.Print PathName

Dim retVar As Long
retVar = Shell(PathName)



End Sub

I still get the same error. Thanks though!
 

spikepl

Eledittingent Beliped
Local time
Today, 20:19
Joined
Nov 3, 2010
Messages
6,142
In addition, Shell does not tolerate spaces in paths, so you need to do this:

retVar=Shell( Chr(34) & PathName & Chr(34), SomeParameterLookItUpInTheDocs)

BTW:
To open a document the easier things is to use the FollowHyperlink method (look it up in the help file)
 

pr2-eugin

Super Moderator
Local time
Today, 19:19
Joined
Nov 30, 2011
Messages
8,494
So Debug.Print, shows this?
Code:
S:\Vente\Vendeurs\Marc\CRM\DOCS\Diligences KYC - LABFT - V 2013 04 23.pdf
Are you sure the File exists?
 

mor

Registered User.
Local time
Today, 20:19
Joined
Jun 28, 2013
Messages
56
Positive. I copied and pasted the file path.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 19:19
Joined
Sep 12, 2006
Messages
15,634
as spike said in #4

it might be easier to test this with

application.followhyperlink PathName
 

Cronk

Registered User.
Local time
Tomorrow, 04:19
Joined
Jul 4, 2013
Messages
2,771
The Shell function is expecting an executable program, not a file name of a pdf document.

You should be looking at something like
retVar = Shell("PathNamePDFReader.EXE PathNamePDF Document")

This is an example to start Excel and open a spreadsheet
retVal=Shell("C:\PROGRAMS\Microsoft Office\Office10\Excel.EXE " & Chr(34) & Me.txtFileName & Chr(34))
 

mor

Registered User.
Local time
Today, 20:19
Joined
Jun 28, 2013
Messages
56
Thanks ! The application.followhyperlink method worked perfectly.

In what case would it be preferable to use the shell method as opposed to the follow hyperlink ?

Thank,
MOR
 

Users who are viewing this thread

Top Bottom