PDA

View Full Version : Hyperlinks and plain text content controls bug



Hawkansson
01-05-2017, 03:27 AM
Hi,

Do the following:

Open a new document.
Insert a table with one cell only
Insert a Plain text content Control in the cell and write some text
Below the table, write some text and bookmark it with the name "test"


Copy the following into a new module and run it:


Sub test()
Dim CellRange As Range
Set CellRange = ActiveDocument.Tables(1).Range.Cells(1).Range
CellRange.Hyperlinks.Add CellRange, "#test"
End Sub


The plain text content control will now have a hyperlink pointing at the bookmarked text below.

Now save it as .docm, close it and reopen it. Word will now complain that the document can't be opened and that Word found an error with its content. If the file is recovered Word removes the hyperlink.

This must be a bug right? It seems like a plain text content control can't be hyperlinked, the hyperlink option is greyed out when trying to manually add the hyperlink to the content control, but when referencing the cell range in the hyperlinks.add method Word believes it's ok anyway.

But it seems OK with a rich text content control though!

gmayor
01-05-2017, 05:34 AM
The clue is in the name 'Plain Text'. A plain text control can only support plain text. A hyperlink is not plain text.

Hawkansson
01-05-2017, 05:57 AM
Yeah, agreed. But I mean, shouldn't Word throw an error when trying to hyperlink a plain text control as described above? I ended up spending a couple of hours searching for why my document was broken when reopening the file.

gmaxey
01-05-2017, 06:13 AM
Word 2010 does throw a RTE 4103 Out of Memory error. Word 2016 doesn't. Entire ranges of plain text controls can be formatted so "PLAIN" text is a bit misleading. Yes, I suppose it could be considered a bug.

Kilroy
01-05-2017, 07:14 AM
Instead of the "plain text content control" use a "repeating section content control" This worked for me in Word 2016.

gmaxey
01-05-2017, 12:32 PM
For the likely intended purpose, inserting the hyperlink text to a rich text CC range might be more appropriate. You will have to ensure that range is not showing placeholder text or you receive the same RTE4103 mentioned above.

macropod
01-05-2017, 05:49 PM
I suppose it could be considered a bug.
Nah, probably just an undocumented feature :whip

Hawkansson
01-09-2017, 06:33 AM
OK, thanks for the input everyone.