Search code examples
vbafile-ioopenfiledialog

I have the file name open...Now how do I actually get the file itself to open?


I have a code that allows me to use an open file dialog to select a file. Once selected, the file path displays in Form3. What I'm trying to do from there is click Command_Button1 (Open) and physically open the file.

I can provide codes and JPEGs...but won't cloud this up until it is necessary :) I'm not using Common Dialog so the code is somewhat lengthy.

I looked online for a few hours yesterday and the closest I got was how to get it to open an Excel file...but this isn't Excel.

P.S. I'm new to VBA...so if this isn't as simple as a few lines of code and I'm missing the difficulty of it, please let me know. It seems like it should be a simple enough process...

Edit 1: @mehow, Do you think it could be because the whole path name isn't displaying? I double clicked Open and nothing happened like you saidJPEG


Solution

  • If you already know the path then..

    Private Sub CommandButton1_Click()
        dim myPath as String
        myPath = "C:\files\file1.exe"
        Dim shell As Object
        Set shell = CreateObject("Shell.Application")
        shell.Open myPath
    End Sub