How do i open exe files through command button, thanks for your help
Printable View
How do i open exe files through command button, thanks for your help
Search the Forumfor ShellExecute
Ok thanks
Hi i have tried ShellExecute "c:/program.exe"
and i have tried Shell "c:/program.exe"
and both do not work what im i doing wrong thanks
Welcome to VBForums :wave:
That depends entirely on what "do not work" means in this case (it nearly always means something different). For example, if there is an error message, it will briefly explain what you are doing wrong.
One obvious issue with what you posted is that you are using / (for unix and the web) when you should be using \ (for Windows).
this is my code, please help its not working
Code:Private Sub Command1_Click()
Shell "C:\Documents and Settings\andrew\My Documents\vb6.0\OS001\MXPWord2010\mxpword2010.exe"
End Sub
Tryvb 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 Private Const SW_SHOWNORMAL = 1 Private Sub Command1_Click() ShellExecute Me.hwnd, vbNullString, "C:\Documents and Settings\andrew\ " & _ "My Documents\vb6.0\OS001\MXPWord2010\mxpword2010.exe", _ vbNullString, "C:\", SW_SHOWNORMAL End Sub
i have tryed it and still dose not work, maybe im doing somthing wrong.
What does "not work" mean? Are you getting an error?
it just high lights it in blue and says Compile Error and Syntax Error
Both your and Hack's code compile OK -what exactly is bing highlighted in blue ?
Im i doing this right
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
Private Const SW_SHOWNORMAL = 1
Private Sub Command1_Click()
ShellExecute Me.hWnd, vbNullString, "C:\Documents and Settings\andrew\ " & "My Documents\vb6.0\OS001\MXPWord2010\mxpword2010.exe", _
16#
vbNullString , "C:\", SW_SHOWNORMAL
End Sub
You must get rid of the blank lines between lines that are continued with the "_" character:
and BTW this looks nothing like the code you posted in Post #6, were we meant to guess what code you were actually using ?Code: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 Const SW_SHOWNORMAL = 1
Private Sub Command1_Click()
ShellExecute Me.hwnd, vbNullString, "C:\Documents and Settings\andrew\ " & "My Documents\vb6.0\OS001\MXPWord2010\mxpword2010.exe", _
16#, vbNullString, "C:\", SW_SHOWNORMAL
Hi it high light ShellExecute and an error comes up and says Compile Error or Arguments or Invalid Property Assignment.
and this is my code
Code:Private Sub Command1_Click()
ShellExecute Me.hwnd, vbNullString, "C:\Documents and Settings\andrew\ " & "My Documents\vb6.0\OS001\MXPWord2010\mxpword2010.exe", _
16#, vbNullString, "C:\", SW_SHOWNORMAL
End Sub
What's that 16# parameter? You're passing 7 parameters and the function only takes six. Try
Code:ShellExecute Me.hwnd, vbNullString, "C:\Documents and Settings\andrew\My Documents\vb6.0\OS001\MXPWord2010\mxpword2010.exe", vbNullString, "C:\", SW_SHOWNORMAL
remove this: 16#,
(which is part of the line numbering from Hack's post, and you haven't got any of the other numbers)
What is the "16#" in your line of code? That was never there before. Refer to your own Post #6 in this thread.
ok thanks all ove you it works thanks agine
Shell() would have worked fine. All that was needed was to use quotes around the file path because of the spaces in it:
I'm not sure why so many people want to use an API call when it isn't required.Code:Private Sub Command1_Click()
Shell """C:\Documents and Settings\andrew\My Documents\vb6.0\OS001\MXPWord2010\mxpword2010.exe"""
End Sub
I suspect, in this case, it's because we were anticipating the next question......