Shell (Opening files)

R

Richard

My Code is below and I am getting an "Invalid procedure
ccall error. If I change the string to the literal path
("C:\Documents and Settings\Richard\My
Documents\Office\test file.xls") I still get the error,
how can I get this to work? The code errors out on the
line "Shell (strPath), vbNormalFocus.

Private Sub lstbox_DblClick(Cancel As Integer)
On Error GoTo Errhand
Dim strPath As String
strPath = Me.lstbox.Column(3)
Shell (strPath), vbNormalFocus

GoExit:
Exit Sub
Errhand:
MsgBox Err.Description & Err.Number
Resume GoExit

End Sub

Thanks for your help in advance..

Richard
 
T

Trent Argante

Richard,
If Gerald's suggestion doesn't work, then view the actual
value of strPath (via a break or MsgBox), so as to verify
the value being returned by "Me.lstbox.Column(3)".
HTH
Trent
 
A

Adrian Jansen

I dont think you can directly open a data file using Shell. But you can run
an executable, and use its command line arguments to open the correct file.
Something like

strPath = "excel.exe C:\Documents and Settings\Richard\My
Documents\Office\test file.xls"

Should work.

Even easier is to use:

strPath = "C:\Documents and Settings\Richard\My
Documents\Office\test file.xls"

FollowHyperlink strPath


--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
T

Trent Argante

Richard, I just clued in. You can't directly open just any
file via Shell because you're functioning in DOS when you
use shell. You have to think "command line". Change your
literal to <pathToExcelApplication> <pathToFile>
For example, "c:\ms-office\excel.exe C:\Documents and
Settings\Richard\My Documents\Office\test file.xls"
And like Gerald suggested, change your code to
Shell strPath, vbNormalFocus
Give this a test, and if it works, replace the literal.
And of course you will have to update your ListBox
control's values
HTH
Trent
 

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