I have a shell command, to execute a program with additional arguments.

Shell "C:\Program Files\uvnc bvba\UltraVnc\vncviewer" & " " & Range("$G3")

The cell G3 contains an IP address I wish to start the program with.

I have no issues starting the command from a command button, but what i wish to do is to start the program with arguments from a hyperlinked cell, using:

= HYPERLINK("C:\Program Files\uvnc bvba\UltraVnc\vncviewer" & " " & Range("$G3"))

But the hyperlink can't open the program with optional arguments.

Is there someway I can open the program from hyperlink with the optional arguments?


figured it out using VBA:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Application.Intersect(Target, Range("range here")) Is Nothing Then
   Call Shell("program location" & " " & Target)

Now I double click on a cell in the sheet containing the IP, and that will run my program with that IP.


Excel hyperlinks are good for opening web pages, PDF files, or other files that are compatible with Microsoft Office. But there are certain issues when using a hyperlink to open a command file like EXE, BAT, CMD, VBS, etc. For example:

• A warning dialog box with OK/Cancel buttons must be negotiated.

• It is not convenient to add command line arguments, especially if they depend upon other cells.

• The command file’s path might be difficult to specify, especially if the Excel file is moved.

• When a command file’s shortcut is specified, its type (.LNK) must be included.

• A shell window will flash when long or complex script files like CMD or VBS are opened.

The technique described here addresses these issues without impacting standard Excel hyperlinks: http://blog.contextures.com/archives/2017/09/14/excel-hyperlinks-run-command-files/

This solution adds text that looks like RUN::COMMAND to the hyperlink’s cell, then process that text using VBA added to the worksheet’s FollowHyperlink event code. For example, if the hyperlink’s cell displays

This cell is a hyperlink to RUN::"Notepad.exe" "SomeFilePath.BAS"

then the specified BAS file will be opened in Notepad.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.