Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

View File from FileListBox

Status
Not open for further replies.

LFC8

Programmer
Nov 18, 2004
45
0
0
GB
Hi

I'm wanting to view a selected PDF file from a FileListBox, I'm trying the shellexecute command but i'm getting no joy!

Any ideas?

TIA

Private Sub cmdOpen_Click()
If File1.Selected(i) = True Then
Shell File1.Path & "/" & File1.FileName, SW_SHOWNORMAL
End If
End Sub
 
Try using the code I included below.

I got this awhile ago from a thread on this site. You should be able to adapt it for your use


Sub OpenDocument(DocPath As String)
'The following code will open a document using the
'application that is registered for that file type.
'This includes URLs, UNCs & paths.
'e.g.
'OpenDocument "'OpenDocument "C:\My Documents\Word.doc"
'OpenDocument "C:\My Documents\Acrobat.pdf"

Dim A As Long
A = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & DocPath, vbMaximizedFocus)

End Sub
 
Are you having troubles opening the PDF, or troubles getting the proper item that was selected in the File1 control?
 
waytech2003
If you want to use someone else's work as a lump, it's easier (and more polite) to just refer others to the original, rather than just copying it. As in this case it's faq222-2066

LFC8
You're almost there, but you need to loop through the FileListBox to find which one IS selected. Use a For...Next loop around your If...EndIf code in a loop from 0 To File1.ListCount - 1, and add the Shell line from the faq referred above, and you will get there.

Come back if you're still struggling

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Thanks waytech2003

That works perfect, thanks for all your guidance
 
LFC8
Glad it helped you.

johnwm
If I had remembered where I had gotten it, I would have linked to it. I copied and pasted it from a program I wrote awhile back. Sorry, next time I will just ignore helping.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top