+ Reply to Thread
Results 1 to 6 of 6

how to open a program through VBA excel userform

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-08-2011
    Location
    Leicester, England
    MS-Off Ver
    Excel 2007
    Posts
    157

    how to open a program through VBA excel userform

    Currently having error problems with trying to open an MS project form from an excel userform.

    Private Sub cmdDash_Click()
    
    Dim x As Variant
    Dim path As String
    Dim file As String
    
    path = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office"
    file = "S:\Information\Design Systems Engineering\CFD Methods\KG\Projects\HPC Blank to forecast.mpp"
    
    x = Shell(path + " " + file, vbNormalFocus)
    ' figure out why wont open the file
    
    End Sub
    Does anyone see any problems with this it keeps prompting me file error on the shell path line

    thanks in advance
    Last edited by kieranbop; 09-13-2011 at 05:46 AM.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: how to open a program through VBA excel userform

    Hi Keiran

    Don't you have to specify a program to open the file? i.e Project, your path only goes to the folder it is contained in

  3. #3
    Forum Contributor
    Join Date
    09-08-2011
    Location
    Leicester, England
    MS-Off Ver
    Excel 2007
    Posts
    157

    Re: how to open a program through VBA excel userform

    I assumed that path went to the program I'm using then the file went to the folder and name of the file being used? or am I completely wrong in what I'm thinking?

  4. #4
    Forum Contributor
    Join Date
    09-08-2011
    Location
    Leicester, England
    MS-Off Ver
    Excel 2007
    Posts
    157

    Re: how to open a program through VBA excel userform

    sorry im not completely awake yet

    Private Sub cmdDash_Click()
    
    Dim x As Variant
    Dim path As String
    Dim file As String
    
    path = ("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\microsoft office project 2007.lnk")
    file = ("C:\Users\u544835\Documents\KG\Projects\HPC Booking\hPC Blank to forecast.mpp")
    
    
    x = Shell(path + " " + file, vbNormalFocus)
    ' figure out why wont open the file
    
    End Sub
    correct what you mentioned I think but now I'm prompted with Invalid procedure/call arguement on the shell line now

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: how to open a program through VBA excel userform

    tell me about it!!

    I think it has to be the actual program and not a shortcut?

  6. #6
    Forum Contributor
    Join Date
    09-08-2011
    Location
    Leicester, England
    MS-Off Ver
    Excel 2007
    Posts
    157

    Re: how to open a program through VBA excel userform

    different way approached to get it to work someone at work sent me, thought id post here for others possibly

    Option Explicit
    
    Private Type SHELLEXECUTEINFO
       cbSize As Long
       fMask As Long
       hwnd As Long
       lpVerb As String
       lpFile As String
       lpParameters As String
       lpDirectory As String
       nShow As Long
       hInstApp As Long
       lpIDList As Long
       lpClass As String
       hkeyClass As Long
       dwHotKey As Long
       hIcon As Long
       hProcess As Long
    End Type
    
    Private Const SEE_MASK_NOCLOSEPROCESS = &H40
    
    Private Declare Function ShellExecuteEX Lib "shell32.dll" _
       Alias "ShellExecuteEx" (SEI As SHELLEXECUTEINFO) As Long
    
    Public Sub VBShellExecute(FPath As String)
    
       Dim SEI As SHELLEXECUTEINFO
       With SEI
         .cbSize = Len(SEI)
         .fMask = SEE_MASK_NOCLOSEPROCESS
         .hwnd = 0
         .lpVerb = "open"
         .lpFile = FPath
         .lpParameters = vbNullChar
         .lpDirectory = vbNullChar
         .nShow = 0
         .hInstApp = 0
         .lpIDList = 0
       End With
       Call ShellExecuteEX(SEI)
    
    End Sub
    Private Sub cmdDash_Click()
    
    Dim file As String
    
    file = ("C:\Users\u544835\Documents\KG\Projects\HPC Booking\hPC Blank to forecast.mpp")
    VBShellExecute file
    
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1