2

I am adding a hyperlink to a document, that includes a query string.

URL example: https://www.website.com.au/paynow/ext?rn=555&amt=95.40

I add this to the document like so -

Dim hyperlink As Word.Hyperlink = WordDocument.Hyperlinks.Add(Me.Range, URL, "", "", "Click me to visit the website")

This opens the website and ignores the query string passed in (basically running https://www.website.com.au.

If I copy the hyperlink link directly (open the document, right click on the hyperlink and select "copy link"), then open a browser and paste it --> the url loads correctly, with the query string being used.

I have checked through fiddler, and it seems like the document add-in is using the final re-direct URL returned. From reading, it seems this could also be a known issue with the Office product?

Also - if I (programatically) take the same URL I'm adding to the hyperlink and add it to a Process.Start("URL"), it loads perfectly fine.

[I even tried encoding the URL - no difference].

Any ideas, starting to go crazy here?

Thanks in advance.

Hexie
  • 3,955
  • 6
  • 32
  • 55
  • Can you add your Fiddler traces? Word normally makes a first request to the URL itself to check if the URL addresses a Word document (and if so, downloads and opens the document). Only after that, the URL (or maybe a redirected URL? --> Fiddler will tell you) is passed to ShellExecute which then opens the URL in the default browser. In your case, it might also be the case that the HTTP request is missing an authentication cookie and you then simply get redirected to the start/login page. – Dirk Vollmar Oct 25 '16 at 07:33
  • @Dirk Vollmar There's not much in the traces that'll help, word does make the first call and get back a redirected url, which does not contain the query string as those values are used once and hidden from the url. I'm wondering if there is any other way to get around what seems to be a limitation with the hyperlinks object. Or maybe to tell word to not make a check first and just load the page. – Hexie Oct 25 '16 at 07:42

1 Answers1

2

The reason is be the default behavior of Word, which first checks whether the URL addresses a Word document (and if so, downloads and opens the document).

This behavior can be changed by adding the following Registry key (replace the Office version accordingly):

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\
    Office\15.0\Common\Internet\ForceShellExecute:DWORD=1

Further information can be found here:

Community
  • 1
  • 1
Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
  • Thanks for this, I've seen the suggestion in a few other posts, but I was really hoping to avoid the registry... I'll give this a try but i am really hoping for a possible fix without a reg hack. – Hexie Oct 25 '16 at 08:03
  • So i've tried using this solution, whether I add the reg key manually or run the microsoft "fix" - it still doesn't fix the issue. Even with the reg key in place, the hyperlink still opens the URL with the query string lost. – Hexie Oct 25 '16 at 20:39
  • 5
    Ok, seems after some debugging and one or two restarts, I managed to get the reg key idea working BUT - FYI --> It had no impact on the Office\VERSION number, and the key had to be inserted into the following path: HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Office\9.0\Common\Internet (basically following this page): https://support.microsoft.com/en-us/kb/218153 – Hexie Oct 25 '16 at 21:11
  • It is not working with Chrome as Default Browser. I needed to setInternet Explorer as Default user. *FacePalm* – maxbit89 May 09 '19 at 08:18