Discussion Locked

VB: how to open windows application

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Using VB scripting, how do I open a notepad file or a word file?

7 replies

by tclere

You can use the ShellExecute API function. This will open any file with it's associated application.

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

Sub OpenSomeFile()
Dim hWnd As Long
Dim sFile As String
sFile = "C:\Test\SomeFile.pdf"
Call ShellExecute(hWnd, vbNullString, sFile, vbNullString, vbNullString, vbNormalFocus)

End Sub

by rrv

Two ways of doing this.
1. Use Shell( CreateProcess and WaitForSingleObject to do syncronous start of any windows application.
If you want the second method, i can give code in VB or youcan get sample code in any latest MSDN help.
All the best.
RV

This discussion is closed to new replies.