![]() |
#1
|
|||
|
|||
![]()
I have a word form with a specific Rich Text Content Control that I'm wanting to have normal text and a hyperlink(s). I know it is possible to have both.
I created a userform with TextBox(s) that will fill some legacy formfields and a Rich Text Content Control via it's Tag. I've gotten the coding for that much to work! I also have a userform with TextBox(s) that will create a hyperlink at the current currsor position. The hyperlink display text doesn't match the actual link which is what I'm wanting. So that code works too! So here's my question / problem: I'm wanting the hyperlink(s) to be in the same Rich Text Content Control along with normal text that is currently being filled with a userform. The contentcontrol isn't locked so I can currently click anywhere in the contenetcontrol right now and use my other userform to insert the hyperlink(s) inside it. Is it possible to do all of this within just one userform? I thought I might could combine the two userforms and have the user when typing the main contents of the contentcontrol portion, to type in the hyperlink display text where they're wanting the hyperlink(s) to be placed. Then on the hyperlink portion of the userform they'll type the hyperlink display text again in the display text box and the web address in the web address box.Then have the code when the Done button is clicked: Place the contents in the content control as it does now. Then search the content control for the hyperlink display text entries and convert/replace them with the appropriate hyperlink(s). I'm not sure what they best way to do this would be. Any help would be much appreciated. Userform code that fills in the formfields and contentcontrol: Code:
Private Sub cmdDone_Click() Dim qtyBox As String Dim markBox As String Dim descriptionBox As String Dim oCC As ContentControls Set oCC = ActiveDocument.SelectContentControlsByTag("idMaterial") 'Validate key entries If Me.qtyBox.Value = "" Then MsgBox "You must enter a Quantity." Exit Sub End If If Me.markBox.Value = "" Then MsgBox "You must enter the Mark." Exit Sub End If If Me.descriptionBox.Value = "" Then MsgBox "You must enter the Description." Exit Sub End If ActiveDocument.FormFields("qtyText").Result = Me.qtyBox.Text ActiveDocument.FormFields("markText").Result = Me.markBox.Text oCC(1).Range.Text = Me.descriptionBox.Text Unload Me lbl_Exit: Exit Sub End Sub Code:
Private Sub cmdInsertHLink_Click() 'Declare variables Dim dspText As String ' Display Text for hyperlink Dim webAddrss As String ' Web / Desitnation Address 'Validate key entries If Me.dspTextBox1.Value = "" Then MsgBox "You must enter Display text." Exit Sub End If If Me.webaddrssTextBox1.Value = "" Then MsgBox "You must enter the Web Address or Link." Exit Sub End If 'Write the hyperlink ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _ Me.webaddrssTextBox1.Text, SubAddress:="", ScreenTip:="", TextToDisplay:= _ Me.dspTextBox1.Text 'Update fields and toggle codes. With ActiveDocument.Fields .ToggleShowCodes .Update End With Unload Me lbl_Exit: Exit Sub End Sub Last edited by odin; 09-11-2014 at 10:53 AM. |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to copy userform text and formfield contents to outlook? | odin | Word VBA | 7 | 09-09-2014 11:56 AM |
![]() |
BoringDavid | Word VBA | 5 | 05-09-2014 09:08 AM |
cross reference hyperlinks to text box | nothing_kills | Word | 4 | 11-25-2013 09:21 AM |
![]() |
DrDOS | Excel | 2 | 03-21-2012 03:53 AM |
![]() |
Dolfie_twee | Word VBA | 1 | 06-22-2010 07:54 AM |