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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running/opening external files from code 1

Status
Not open for further replies.

Refresh256

Technical User
Feb 28, 2005
2
GB
Hi,

I have a bunch of files (mostly pdf) and I would like to select one from a Userform combo box [I can do that] and then have that file opened in its parent application.

I can open microsoft documents, but struggle with external apps such as adobe. I would settle with outputting the file path to a cell as a hyperlink [I can do that too], and then 'activate' the link from code, but I can't find any way to do "cell.click-on-hyperlink" from code.

Any suggestions would be greatly received... thankyou
 

Open a file with default file association
Code:
Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
    ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

[blue]Then call it like this:[/blue]

ShellExecute(0&, "open", sFileName, vbNullString, vbNullString, vbNormalFocus)
Or, start any file;
Code:
Public Sub OpenDocument(strDocPath As String)

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

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top