PDA

View Full Version : [SOLVED:] Hidden Text Breaks Hyperlink



rruckus
03-05-2012, 08:44 AM
This seems to be a really bad Word bug/behavior. If anyone has any ideas on how to fix or workaround it, I would be very grateful!

1. Create a new blank Word document (I'm in 2010)
2. Type two paragraphs and make the second a Heading style
3. Select a word in the first para and choose Insert Hyperlink
4. Make a link to the heading you created in step 2 by using the "Place in this document" window.
5. Select the first paragraph that contains your link (not the heading) and make it Hidden (Home TabFontEffectsHidden)
6. Immediately Save and reopen your document

Now your link will be broken! Try to ctl-click and it won't work OR put your cursor in the link and hit f9 and it will change the link text to "Error! Hyperlink reference not valid."

Underneath the OOXML it looks like the target is getting set to an external href which it obviously shouldn't be! I need to have a workaround or fix for this (VBA or user is fine).

fumei
03-05-2012, 11:11 AM
Why would you wxpect Hidden text to function like not Hidden text?

rruckus
03-05-2012, 12:42 PM
Are you being facetious? Did you try the example?

This is a bug in the way the OOXML gets written by Word to the disk. After more tests, I found that the problem is that Word will incorrectly change the internal link to an external link in the OOXML by adding an id to the w:hyperlink element and creating an entry in the .rels file pointing to nowhere.

It gets worse... try working with the link using VBA after re-opening the document and it will CRASH Word everytime.

fumei
03-05-2012, 01:27 PM
1. Yes I did try it.
2. No, I was not being facetious. I was trying to understand the point of making it Hidden. If it IS Hidden (and you have Show/Hide as Hide) then you can not see the hyperlink. So...what is the point of this???

And finally...#3. It works for me. The cursor goes to the location indicated by the hyperlink.

Frosty
03-05-2012, 01:39 PM
I'm seeing a bit of a difference (hovering shows an external file rather than the current document).

But yes, this looks like a "bug" in that it is unanticipated behavior.... So, now what?

Why do you need the link to be hidden text? My gut reaction is that a link which is hidden may be encountering some sort of "get rid of metadata" functionality. There may be some settings which you can reduce the behavior (such as always showing fieldcodes)

I'm less interested in the Word crashing, as that is happening because you have a document element in a "bad" state. And, unless you need help documenting the bug for Microsoft, you're probably more concerned with preventing getting to the "bad" state...

So, can you detail out some of your requisites for why you would want a link to be formatted as hidden?

Frosty
03-05-2012, 01:44 PM
And, as an addition... while I'm not getting a word crash (since I'm just dealing with the user experience at the moment, not the VBA stuff), I'm seeing the content of the link disappear in the scenario you're talking about...

(i.e., ALT+F9 initially shows HYPERLINK \l "_To_Change_the" -- which is the hidden bookmark name -- and then that gets wiped out after some saving and re-opening).

However, if I show fieldcodes, when I re-open the document, it retains that info.

What other testing have you done?

rruckus
03-05-2012, 02:25 PM
I obviously wouldn't post this unless there was a reason, so here it is:

I have a button that runs VBA code that shows/hides the first subsection of every section (sections are defined by Content Controls) because this text is instructional text. Sometimes users show the hidden text and edit the text or put hyperlinks in the instructional text. Othertimes they don't want to see the instructions so they hide the text. It's this combination of creating links in the instructional text, hidding, saving and re-opening the document that breaks the link. This is not only a valid scenario, it is exactly why many people use hidden text in the first place!

If you think that the link breaking is the expected behavior, then why doesn't it happen for web links, cross-references, images, etc?

To reproduce, make sure you follow my steps exactly. I've reproduced this on 4 different machines now, so it's not just me.

Frosty: The crash only happens when you use VBA after re-opening the document. Try something as simple as putting your cursor in the broken link and run this VBA code from the immediate window and it will crash (assuming you reproduced the bug correctly):


? Selection.Hyperlinks(1).Address

rruckus
03-05-2012, 02:31 PM
Frosty: Yah I thought about turning on field codes or similar but then I need to store the fact that I changed it somewhere and turn the fieldcode back on when I open the document. Messy to say the least.

I *THINK* I have a workaround, but I need to test it more. If I register for the Document_Save event and loop through all the links, I can find any internal hyperlinks that Word has messed up and set them to an explicit external weblink with the hashtag character instead of leaving the target address blank (why Word creates an empty target Address I have NO IDEA). This seems to fix it:


Dim oLnk As Hyperlink
For Each oLnk In Doc.Hyperlinks
If oLnk.Range.Font.Hidden = True Then
If oLnk.Address = "" And oLnk.SubAddress <> "" Then
'if address is empty, it's an INTERNAL LINK but Word will convert to an EXternal link, and will break the link on Open, _
so we need to set a better Address by adding #
oLnk.Address = "#" & oLnk.SubAddress
End If
End If
Next oLnk

Frosty
03-05-2012, 03:20 PM
Yeah, if that works, you're probably good.

Since you thought of using the Document_Save (don't know if this is for a specific document, or you're putting it in a global addin), but you could just re-purpose the Document_Close event and simply unhide any hidden text, right? The specific of the bug is that
1. You close the document while text is hidden (not formatted to be hidden, but also not being viewed).
2. When the document is opened back up... a link that is "hidden" becomes broken.

If you've applied a style to these areas of the document, I would simply change that style to not be hidden when the document is closed, and when you re-open, make it hidden again.

It may save you from having to "fix" all the links, since you're avoiding the "bad" scenario entirely with this. Of course, really "fixing" the links is probably the right way to go, but just throwing stuff at the wall to see if it sticks.

Might this also be related to automatically updating links on open? Word rarely "breaks" things automatically on open... there may be a global application setting which doesn't really matter in your environment, and then you avoid all of this processing...

rruckus
03-05-2012, 05:08 PM
Yes I could do that but it would only catch my sections that have the style applied when in fact this bug would also occur if a user decides to hide some text on their own outside of my button, which is a possibility, so the only way to really catch all situations is to analyze all links on save.

The bug isn't on Open, it's actually already broken when Word writes out the OOXML on SAVE (you can see it by renaming your file to a zip and viewing the document.xml and the related _rels.xml file). It's just hard to see without opening the file so it appeared to be on Open.

Interestingly enough, even if you ask Word for the OOXML or XML on the range of these broken hyperlinks it will fail even before saving, so maybe it's just their internal OOXML code that's busted.

Frosty
03-05-2012, 06:14 PM
That seems strange, since Word often validates the file on open, rather than on Save, but I believe you. I still wonder if there isn't a global setting affecting this bug.

But you do have the steps necessary to recreate the issue on a clean version of Word, which I suspect you could document and have added to a Word 2010 patch in the future.

As an fyi-- it's actually not that hard to open a case with Microsoft on this kind of issue, when you can create duplicate it with such simple steps in a "clean" word process (i.e., create a .docm in a word process you've launched via "winword /a" from a run command). Put a little code and the steps above to generate the issue... and you can have the case added to the bug list.

On to the next bug :)

fumei
03-05-2012, 06:32 PM
Very strange because I have reproduced your steps exactly, and it works fine fo me. There is no broken link, and hovering shows the current file, not an external link. So while I reproduce the steps I can not reproduce the results you describe.

fumei
03-05-2012, 07:27 PM
Is it possible that I have a different build? I received mine directly from Microsoft when I got my MVP. I do not know what else it could be, because I have tried a number of times now and it all works.

I have tried turning on/off field codes. I have tried every combination of Save/Open I can think of. I have tried using VBA for the Show/Hide.

It works fine for me. How odd.

Paul_Hossler
03-05-2012, 07:33 PM
1. Create a new blank Word document (I'm in 2010)
2. Type two paragraphs and make the second a Heading style
3. Select a word in the first para and choose Insert Hyperlink
4. Make a link to the heading you created in step 2 by using the "Place in this document" window.
5. Select the first paragraph that contains your link (not the heading) and make it Hidden (Home TabFontEffectsHidden)
6. Immediately Save and reopen your document



FWIW, I've had consistant and as expected results if I hide the text, and then insert a hyperlink to a Heading paragraph

Steps 1, 2, 3, 5, 4, and 6

Paul

rruckus
03-06-2012, 08:59 AM
Thanks for everyone's help looking into this issue.

Paul, great observation! I'm getting the same results as you, when I switch the order of 4&5 my link is OK, but note that the link is external when you do this. If you hover over the link it will start with "file:///". I think that really confirms it is indeed a bug, because order should not matter!

But obviously there's no way that I can force my users to hide the instructions before creating their links, so that doesn't get me anywhere.

Fumei: Weird that you can't reproduce it, there's six machines I've had it on now and at least 3 different Word versions. But I didn't get those from Word MVP. I have Microsoft Office Professional Plus 2010, Version" 14.0.6112.5000 (32-bit).

Frosty: I've been looking for a setting that would change this, but I don't see one. I think that Paul's test is very telling though because if it was a setting, the link would be broken no matter what the order of steps 4&5 are.

I don't have time to report to MS, but feel free to if any of you guys want to!

rruckus
03-13-2012, 06:11 AM
Why do you need the link to be hidden text? My gut reaction is that a link which is hidden may be encountering some sort of "get rid of metadata" functionality. There may be some settings which you can reduce the behavior (such as always showing fieldcodes)

Read the thread!