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!

Open any document file from VB6 1

Status
Not open for further replies.

BasicBoy

Programmer
Feb 22, 2008
156
ZA
My VB6 program has a link to a document file (like a .txt, .pdf or .jpg) on a label (say lblDoc.caption) on the form which points to a file on his C drive.
I need to open the file for the user using the default program on his computer for that type of document in order for him to display it in whichever format it is in.
I think I need to use the SHELL function.
How do I establish his default program for that type of file and what is the syntax to open it?
Thanks so much
 
Let the shell do all the heavy lifting:

Code:
[blue]With CreateObject("shell.application")
    .Open <document>
end With[/blue]
 
I use something like this:

Code:
Public Sub OpenDocument(strDocPath As String)
Dim G As Long
G = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & strDocPath, vbNormalFocus)
End Sub

Just pass the full path with the file name.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Oops.

[tt].Open <document>[/tt]

should have read

[tt].ShellExecute <document>[/tt]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top