View Single Post
 
Old 03-27-2012, 03:58 PM
EricT EricT is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Mar 2012
Posts: 2
EricT is on a distinguished road
Default word macro that reformats embedded links in a doc

Here's what I am trying to accomplish:

I want to add a subroutine into my word 2007 macro that will take the text and address for an embedded link in a document, and convert it to an href tag that uses the text as the display text, and the address for the html address.

So a line that appears as "go here to get to google" with a blue underline, and when clicked goes to www.google.com, gets replaced with:

<a target="_blank" href="http://www.google.com">go here to get to google</a>

This routine is to be added to an existing macro that I already have that does some other minor formatting, so no need for headers and whatnot.

That's it! If I am not explaining this well enough please don't hesitate to ask me any questions so I can clarify. Thanks!


Editing to add-

Played around with word a bit and I discovered the name of the structure I want to manipulate - I think.

ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
"www.google.com", _
SubAddress:="", ScreenTip:="", TextToDisplay:= _
"FBI Bulletin test display text", Target:="_blank"
Selection.Collapse Direction:=wdCollapseEnd

So it looks like the Address:="inside quotes" and TextToDisplay:= _"inside quotes" are the 2 variables I want to grab, store, and shove into the example string above, with that static code around it. I have a few lines in this macro that say, find underlined text, and replace with html tags around the text, but this one is a touch over my head.

I also want to make sure if there's 5 links in a page that I grab them all as well. Thanks again!

Last edited by EricT; 03-27-2012 at 06:37 PM. Reason: added content
Reply With Quote