Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-28-2012, 01:23 PM
Marrick13 Marrick13 is offline VBA to copy bookmark-hyperlinks to plain text strings Windows XP VBA to copy bookmark-hyperlinks to plain text strings Office 2010 32bit
Competent Performer
VBA to copy bookmark-hyperlinks to plain text strings
 
Join Date: Jun 2006
Posts: 102
Marrick13 will become famous soon enough
Default VBA to copy bookmark-hyperlinks to plain text strings

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
Reply With Quote
  #2  
Old 04-28-2012, 09:02 PM
macropod's Avatar
macropod macropod is offline VBA to copy bookmark-hyperlinks to plain text strings Windows 7 64bit VBA to copy bookmark-hyperlinks to plain text strings Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 04-29-2012, 05:12 AM
Marrick13 Marrick13 is offline VBA to copy bookmark-hyperlinks to plain text strings Windows XP VBA to copy bookmark-hyperlinks to plain text strings Office 2010 32bit
Competent Performer
VBA to copy bookmark-hyperlinks to plain text strings
 
Join Date: Jun 2006
Posts: 102
Marrick13 will become famous soon enough
Default

You're right, Paul - that is ridiculously easy! Thanks much.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to copy bookmark-hyperlinks to plain text strings Rich text/Plain text Content Controls in Template 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
VBA to copy bookmark-hyperlinks to plain text strings Word 2003 - IncludeText Does Not Include Bookmark Text if in a Form Text Control skarden Word 1 12-12-2011 10:39 PM
VBA to copy bookmark-hyperlinks to plain text strings update style of all strings available between two specific strings 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft