I have a document which is populated from a User Form. Data entered in the user form is placed into locked content controls. I do this via a function to unlock the content control, add the data in, then re-lock the content control. This forces users to enter their data via the User Form.
Now I have a situation where my content control needs to be populated with a hyperlink, but I keep getting an out-of-memory error.
How can I get this to work???
I'm calling the function from the following line of code in my UserForm. "Permalink" is the title I've given my content control.
AddCCHyperlink "Permalink", Me.txtPermalink
Function AddCCHyperlink(sCCTitle As String, sLink As String)
Dim CC As ContentControl
Dim rng As Range
For Each CC In ActiveDocument.ContentControls
If CC.Title = sCCTitle Then
CC.LockContentControl = False
CC.LockContents = False
Set rng = CC.Range
'ActiveDocument.Hyperlinks.Add Anchor:=rng, Address:=sLink 'doesn't work
CC.Range.Hyperlinks.Add Anchor:=CC, Address:=sLink 'doesn't work
'Selection.Hyperlinks.Add Anchor:=Selection.Range, Address:=sLink 'doesn't work
CC.LockContentControl = True
CC.LockContents = True