Results 1 to 20 of 20

Thread: [RESOLVED] How to exe files in form

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    13

    Resolved [RESOLVED] How to exe files in form

    How do i open exe files through command button, thanks for your help

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to exe files in form

    Search the Forumfor ShellExecute

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    13

    Re: How to exe files in form

    Ok thanks

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    13

    Re: How to exe files in form

    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

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to exe files in form

    Welcome to VBForums

    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).

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    13

    Re: How to exe files in form

    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

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to exe files in form

    Try
    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    4. (ByVal hwnd As Long, _
    5. ByVal lpOperation As String, _
    6. ByVal lpFile As String, _
    7. ByVal lpParameters As String, _
    8. ByVal lpDirectory As String, _
    9. ByVal nShowCmd As Long) As Long
    10.  
    11. Private Const SW_SHOWNORMAL = 1
    12.  
    13. Private Sub Command1_Click()
    14. ShellExecute Me.hwnd, vbNullString, "C:\Documents and Settings\andrew\ " & _
    15. "My Documents\vb6.0\OS001\MXPWord2010\mxpword2010.exe", _
    16. vbNullString, "C:\", SW_SHOWNORMAL
    17. End Sub

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    13

    Re: How to exe files in form

    i have tryed it and still dose not work, maybe im doing somthing wrong.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to exe files in form

    What does "not work" mean? Are you getting an error?

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    13

    Re: How to exe files in form

    it just high lights it in blue and says Compile Error and Syntax Error

  11. #11
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to exe files in form

    Both your and Hack's code compile OK -what exactly is bing highlighted in blue ?

  12. #12

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    13

    Re: How to exe files in form

    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

  13. #13
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to exe files in form

    You must get rid of the blank lines between lines that are continued with the "_" character:

    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
    and BTW this looks nothing like the code you posted in Post #6, were we meant to guess what code you were actually using ?

  14. #14

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    13

    Re: How to exe files in form

    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

  15. #15
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: How to exe files in form

    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
    Last edited by baja_yu; Oct 18th, 2010 at 01:26 PM. Reason: typo

  16. #16
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to exe files in form

    remove this: 16#,

    (which is part of the line numbering from Hack's post, and you haven't got any of the other numbers)

  17. #17
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to exe files in form

    What is the "16#" in your line of code? That was never there before. Refer to your own Post #6 in this thread.

  18. #18

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    13

    Re: How to exe files in form

    ok thanks all ove you it works thanks agine

  19. #19
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [RESOLVED] How to exe files in form

    Shell() would have worked fine. All that was needed was to use quotes around the file path because of the spaces in it:
    Code:
    Private Sub Command1_Click()
    Shell """C:\Documents and Settings\andrew\My Documents\vb6.0\OS001\MXPWord2010\mxpword2010.exe"""
    End Sub
    I'm not sure why so many people want to use an API call when it isn't required.

  20. #20
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: [RESOLVED] How to exe files in form

    I suspect, in this case, it's because we were anticipating the next question......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width