A client called me asking for help with a problem on one of their Microsoft Excel spreadsheets. They were creating content for their new website that I was in the process of building and wanted to include bookmarks to content they had already created on the site.
Whenever they clicked on a link in their spreadsheet, they received an error “Unable to open <url>. Cannot download the information you requested”. They also tried doing it in Microsoft Word, but received a similar error.
I had them send me the spreadsheet and Word document – I don’t use Microsoft Office, but I do have the readers installed. Strangely enough, I got exactly the same error – which was very perplexing considering that the link itself was completely valid and worked in my browser.
I had them create some test links to other website and found that these worked without a problem. This proved to be a major clue to the problem – it seemed related to the website I was building rather than a problem in Word or anything else.
After a bit of Googling I found a technote that explained that the Office programs will attempt to access the link first before forwarding the URL to your browser to load the web page. If there is an error returned from the website for that URL, Word or Excel will refuse to load it.
On closer inspection I found that web pages on the site I was developing were indeed returning 404 errors. I had set up a basic layer of security prior to site launch by including a conditional in the header template of the WordPress site which checked to see if the user was logged in to WordPress as an editor or administrator, and if not – display an error message explaining the site was coming soon.
The wp_die function I was calling returned a 404 HTTP code to the browser when it output the error message – which is all that Word or Excel could get from the site – thus they believed (correctly) that the URLs were (currently) invalid. When I turned off the security to test it, the links in Word and Excel worked as expected.
The real problem was that Word and Excel provided less than meaningful error messages – if they had just forwarded the request to access the URL to a browser, we would have seen the meaningful error message from the website and worked out what was happening immediately.