VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Launch file and associated program

VB FAQ  (6 Submissions)   Files/File Controls/Input/Output   Visual Basic 3.0   Unknown Difficulty   Wed 3rd February 2021

How do I launch a file in its associated program?
The Shell statement unfortunately only supports launching an EXE file directly. If you want to be able to launch, i.e. Microsoft Word by calling a .DOC file only, you can make your VB application launch the associated program with the document using the following method:

API Declarations


#IF WIN32 THEN
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
Private Declare Function GetDesktopWindow Lib "user32" () As Long
#ELSE
Declare Function ShellExecute Lib "SHELL" (ByVal hwnd%, _
ByVal lpszOp$, ByVal lpszFile$, ByVal lpszParams$, _
ByVal lpszDir$, ByVal fsShowCmd%) As Integer
Declare Function GetDesktopWindow Lib "USER" () As Integer
#END IF
Private Const SW_SHOWNORMAL = 1

Rate Launch file and associated program (9(9 Vote))
Launch file and associated program.bas

Launch file and associated program Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters