1

I want to retrieve a hyperlink to a cell in Excel and then paste this hyperlink in a third party app. Clicking the hyperlink should load Excel with the appropriate workbook and that cell should be selected with the cursor.

The hyperlink should work in Microsoft-related products like OneNote; for example, if I have a workbook "D:\abc.xls" and I want to jump to cell C12, I would make an hyperlink like "D:\abc.xls#C12".

And this would work; however, if I paste this in a non-Microsoft applicaltion it just opens up Excel and the workbook, but the cell isn't highlighted. How can I get this to work?

9
  • As far as I know, no. OneNote does a lot of "funny" stuff. I am user of OneNote 2003 and 2007, and an Office developer since pre Office '95. To this day, OneNote still surprises me on some of the stuff it does. I believe OneNote is using "send-keys" to navigate to the specific cell. Excel maintains the "last-current-position" that it restores when opening a Workbook.
    – AMissico
    May 4, 2010 at 10:08
  • There may be VBA macros that provide this functionality because it is a common request.
    – AMissico
    May 4, 2010 at 10:10
  • @AMissico:I tried the same in "Word" too and it works there too! Regarding the macros I have done some googling around but haven't found similar functionality.
    – Kevin Boyd
    May 4, 2010 at 10:13
  • @Kevin Boyd: When I first noticed OneNote doing this, I used all my "tricks" to figure out how. I gave up after an hour because I had other stuff to do.
    – AMissico
    May 4, 2010 at 10:25
  • The HYPERLINK worksheet function does exactly what you want. Maybe a VBA macros take advantage of this.
    – AMissico
    May 4, 2010 at 10:45

2 Answers 2

1

RE comment

That's what i was suggesting, for example save the following as a .reg and import it

REGEDIT4

[HKEY_CLASSES_ROOT\XLOPEN]
@="URL:Excel Opener"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\XLOPEN\shell\open\command]
@="CSCRIPT.EXE \"C:\\TEMP\\XLOPEN.VBS\" \"%1\""

This makes an XLOPEN:// URL protocol handler thatr when invoked will run XLOPEN.VBS.

Save the following as C:\TEMP\XLOPEN.VBS

rem //get an argument like "XLOPEN://C:\null\text.xlsx/#F55" note extra /
dim arg:  arg = WScript.Arguments.item(0)
dim arr:  arr = (split(ucase(arg), "#"))
rem unmangle the url
dim filename: filename = replace(arr(0), "XLOPEN://", "")
if (right(filename, 1) = "/") then filename = mid(filename, 1, len(filename)-1)
dim xl:   set xl = createobject("excel.application")
xl.Workbooks.Open filename 
xl.range(arr(1)).select
xl.visible = true

Now if you run

xlopen://c:\null\test.xlsx#Q50

or use

<a href="xlopen://c:\null\test.xlsx#Q50">bla bla</a>

Windows will lookup xlopen:// and pass the string xlopen://c:\null\test.xlsx/#Q50 to XLOPEN.VBS which extracts the file path c:\null\test.xlsx1 and opens it, then selects the range after the #.

This works if called in browsers/from the shell/via the windows API, no idea if it will work in the 3rd party app. (You would replace the script with a helper exe)

1
  • Before your post, I tried doing some tests, like I opened internet explorer and pasted the link D:\abc.xls and it opened the file, however if I pasted the link D:\abc.xls#C12 it gives a error message. I thought if it works in word and onenote it should have worked in IE too, I wonder why it's not opening the cell. Thanks for the very elaborate explanation.
    – Kevin Boyd
    May 5, 2010 at 16:53
1

This must be something automagically done by Office apps as the path: abc.xls#C12 taken as a whole is a potentially valid filename itself - if you try to run it from the shell you'll get a "path not found" error.

If you click that link in onenote and look at the command line the resulting instance of excel was opened with there is only the "-embedding" switch which probably means onenote is parsing out abc.xls, launching excel via its automation features then activating C12.

I think if you want that functionality you would need to do the same thing using a helper app and use paths like "C:\your_XL_loader.exe D:\abc.xls#C12".

(If the 3rd party application honors windows protocol handers its trivial to make your_XL_loader.exe associate its self with something like XXX://abc.xls#C12)

3
  • the 3rd party app is a Java app and I don't know how to associate the _XL_loader.exe to associate to a hyperlink. Also the #C12 part of the hyperlink will change depending on what cell I want to highlight.
    – Kevin Boyd
    May 4, 2010 at 11:10
  • Its just a few registry settings: msdn.microsoft.com/en-us/library/aa767914%28VS.85%29.aspx - but it relies on the java app being smart enough to either understand custom url protocol handlers or at least pass them off to the shell.
    – Alex K.
    May 4, 2010 at 11:22
  • I'm sorry, I can't make sense of this, what is _XL_loader.exe? You see I have a java app that will initiate the url request, do you want me to make a helper app that we take this request and then pass it on to excel in a format that excel understands, is that right?
    – Kevin Boyd
    May 5, 2010 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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