0

So basically, I opened Microsoft Word and I went to the developer tab, drew a command button, double clicked it to open VB to write code, I want it to open a specific file. This is the code I wrote

Does not work...

My code I got so far is

Private Sub CommandButton1_Click()
Process.Start ("C:\Program Files\Google\Chrome\Application\chrome.exe")
End Sub

When I click run it comes up with a error saying:

Run-time error '424':
Object required

Can you please fix for me because I have no idea... I just need this one button and that's all.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
user2605552
  • 1
  • 1
  • 2
  • `Process.Start` is VB.NET, not VBA. Look at `Shell` – Tim Williams Mar 24 '14 at 22:56
  • simple google search would bring you to the answer, why does no one use search before they post?!? http://support.microsoft.com/kb/170918 KB article on shellexecute or use the stackoverflow on for using shell http://stackoverflow.com/questions/17956651/execute-a-command-in-command-prompt-using-excel-vba – Sorceri Mar 24 '14 at 23:08

1 Answers1

0

ok this is what you need my friend...

  1. CREATE a new module - if you don't already have one:

    • to do this - its simply done in visual basic
    • then, press: ALT > select: Insert (menu) > select: Module
    • Note: you can change the module name via the properties window - for this example left it default 'Module1'
  2. WRITE up a PUBLIC sub (as below):

    Public Sub StartExeWithArgument()
        Dim strProgramName As String
        Dim strArgument As String
    
        strProgramName = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
        strArgument = "/G"
    
        Call Shell("""" & strProgramName & """ """ & strArgument & """", vbNormalFocus)
    End Sub
    
  3. CALL the sub in the click command private sub:

    Private Sub CommandButton1_Click()
        Module1.StartExeWithArgument
    End Sub
    

ok, enjoy ;)

anthonyc
  • 1
  • 1