Excel (2010) HYPERLINK: how to call a file with command line arguments and spaces in the path?

2

I am working on an Excel-document to make a (project-)folder structure manageable, using HYPERLINKs to important files and folders (Word/Excel, etc.).

Since we are also using TFS, I want to add the possibility to check out and check in right from within the Excel sheet. The one-stop landing and overview page.

If I simply have

=HYPERLINK("C:\work\TF.exe";"simple test")

I get a security warning, but the program executes.

In the end, I want something like

=HYPERLINK("C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\TF.exe status $/MyProject/Documents /recursive";"Find local Check Outs in Document folder")

However, this does not work for spaces in the file path and also for the command line arguments. Is there any way to make this run without using VB? Even if I wrap parts of the hyperlink with quotes (using double double quotes for Excel: "" -> ") does not improve anything, I get "file not found" error.

And.. only only only if I have to use VB (I do not like the security warning), what would be the best way to do this?

Andreas Reiff

Posted 2012-10-25T14:19:13.157

Reputation: 895

Answers

8

An alternative is to create a shortcut with the relevant command line switches embedded in it. Then you can hyperlink to the shortcut. Note that the shortcut has a .lnk extension.

If you'd like to do something more involved than launching a single executable with switches, you could link to a batch script (.bat).

Anthony DiSanti

Posted 2012-10-25T14:19:13.157

Reputation: 235

4Or do the same with a batch file (.bat), which should be more versatile than a shortcut. – Bob – 2012-10-25T15:55:23.483

It does not allow me to use parameters (e. g. a cell with the path), still, it is working fine, just a little overhead right now, and I might go for the VB solution later. Many thanks! – Andreas Reiff – 2012-10-26T15:39:42.550

2

As far as I know, it is not possible to use HYPERLINK like that - except with the nice trick of anthony.

However, spaces in the hyperlink don't matter as long as the path is in quotes.

To solve this you might have to use VBA, if the command-line parameters have to be dynamic or if you don't want to use anthonys approch for other reasons.

This would be a neat fast way:

Shell "C:\Program Files (x86)\Notepad++\notepad++.exe -notabbar", vbMaximizedFocus

or to use your code:

public sub demo()
  Shell "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\TF.exe status $/MyProject/Documents /recursive"
end sub

By the way - usually there is, and should be, a warning, when executing files through hyperlinks. So if you wan't to use HYPERLINK because of "don't like warnings", you got them there too ;)

On the other hand - the VBA solution can avoid warnings, if you sign your Workbook with a trusted signature or use it in a folder, wich is setup as trusted for macros.

Jook

Posted 2012-10-25T14:19:13.157

Reputation: 1 745

Thanks, I might go to this eventually in order to only have the path in one cell, and then have the other cells simply refer this and call different files with parameters. – Andreas Reiff – 2012-10-26T15:40:37.400