468,774 Members | 1,438 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,774 developers. It's quick & easy.

VB with Shell

Hi to everybody,

How to open the files otherthan .exe by using VB

can any body tell with example please

Thank u
Aug 16 '07 #1
3 6534
Stwange
126 Expert 100+
In your declarations at the top of the code, paste:

Expand|Select|Wrap|Line Numbers
  1. Public 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
And then use this function:

Expand|Select|Wrap|Line Numbers
  1. Public Function ShellExec(ByVal strFile As String)
  2.     Dim x As Long: x = ShellExecute(0, "OPEN", strFile, "", "", 0)
  3. End Function
Passing the filepath as a parameter.

Hope that helps.
Aug 16 '07 #2
Stwange
126 Expert 100+
And the example you requested:

Private Sub cmdOpen_Click()
ShellExec("C:\testfile.doc")
End Sub
Aug 16 '07 #3
pureenhanoi
175 100+
In your declarations at the top of the code, paste:

Expand|Select|Wrap|Line Numbers
  1. Public 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
And then use this function:

Expand|Select|Wrap|Line Numbers
  1. Public Function ShellExec(ByVal strFile As String)
  2.     Dim x As Long: x = ShellExecute(0, "OPEN", strFile, "", "", 0)
  3. End Function
Passing the filepath as a parameter.

Hope that helps.
Woa, that's very nice. Sometimes I would be called Shell excute function, but Shell command in VB can't archive parameters with space character.
Aug 17 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by John Bowling | last post: by
8 posts views Thread by Siemel Naran | last post: by
6 posts views Thread by Lauren Wilson | last post: by
5 posts views Thread by bearophileHUGS | last post: by
3 posts views Thread by George Sakkis | last post: by
21 posts views Thread by Tom Gur | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.