471,109 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,109 software developers and data experts.

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 6871
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.