![]() |
#1
|
|||
|
|||
![]()
I want to be able to copy a hyperlink tied to a bookmark to all occurrences of a text string entered in an inputbox, and I don't know whether the code should search and select all finds and replace them with the link or if there are better ways.
In the document I'm working on, I have 16 instances of the plain text "Chapter 22" that I want to convert to HYPERLINK \l "EmotionalGuidanceScale" (still displaying "Chapter 22" as the text) so I can click on any of them and navigate to the EmotionalGuidanceScale bookmark. I started the code for the inputbox and counter, but that's as far as I got. It just occurred to me that after entering the text to be converted, I should display the bookmark list so the bookmark can be selected (not that I necessarily know how to do that!), but I still have the unresolved issue of actually copying the link to the text strings. Code:
Sub CopyFieldCode() Dim Text As String, MyDoc As String, t As String, count As Long, i As Integer MyDoc = ActiveDocument.Range.Text Text = InputBox("Enter text to find (case sensitive)") If Text = "" Then Exit Sub End If t = Replace(MyDoc, Text, "") count = (Len(MyDoc) - Len(t)) / Len(Text) If count = 0 Then MsgBox "There were no occurrences of " & Text Exit Sub End If For i = 1 To count [Here is where I need help; the code snippet below doesn't work] ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", _ SubAddress:="EmotionalGuidanceScale", ScreenTip:="", TextToDisplay:= _ Text End With Next i End Sub |
#2
|
||||
|
||||
![]()
Hi Marrick,
The (ridiculously) easy way to do this without vba is to: 1. Create your hyperlink, including with the 'Chapter 22' display text. 2. Copy the hyperlink to the clipboard 3. Do an ordinary Find/Replace, where - Find = Chapter 22 Replace = ^c
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
You're right, Paul - that is ridiculously easy! Thanks much.
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
michael.fisher5 | Word | 9 | 11-19-2014 06:36 AM |
My plain text post got converted to rich text in a reply, how to convert it back? | david.karr | Outlook | 0 | 01-05-2012 09:46 AM |
![]() |
skarden | Word | 1 | 12-12-2011 10:39 PM |
![]() |
vikrantkale | Word | 1 | 03-28-2011 06:13 PM |
Copy plain text message including sender, recipient, and subject | distancesprinter | Outlook | 0 | 01-22-2010 12:49 PM |