C
CompleteNewb
A Word guru was nice enough to provide me with this snippet that makes Word
hyperlinks HTML ready (find text that's a hyperlink, and wraps said text in
the <a href> tags for export to a text file that's web-ready (and before you
suggest Word's save as html, I can't use that because of the pages and pages
of Microsoft-only html language Word uses; it's far from a clean web page).
One thing this doesn't do, though (which I forgot to mention I needed to
do), is include the Target attribute (ie. when a hyperlink is set to open in
a new window, I need the "Target="_blank" to be included in the <a href>
tag.
So, if I have a hyperlink in Word that is supposed to open the page in a new
browser window, I need to wrap that text with:
<a href="www.whatever.com" target='_blank">This is the hyperlink</a>
Some hyperlinks are supposed to open in a new window, and some are not.
Can someone help me incorporate this particular requirement into the
following code (which currently works great except for not using the target
attribute):
Sub demo()
Dim nLink As Long
Dim hLink As Hyperlink
Dim strText As String
Dim oRg As Range
Const qt = """"
For nLink = ActiveDocument.Hyperlinks.Count To 1 Step -1
Set hLink = ActiveDocument.Hyperlinks(nLink)
Set oRg = hLink.Range
strText = "<a href=" & qt & hLink.Address
If hLink.SubAddress <> "" Then
strText = strText & "#" & hLink.SubAddress
End If
strText = strText & qt & ">" & _
hLink.TextToDisplay & "</a>"
oRg.Text = strText
Next
End Sub
Thanks for any help on this, and for taking the time.
hyperlinks HTML ready (find text that's a hyperlink, and wraps said text in
the <a href> tags for export to a text file that's web-ready (and before you
suggest Word's save as html, I can't use that because of the pages and pages
of Microsoft-only html language Word uses; it's far from a clean web page).
One thing this doesn't do, though (which I forgot to mention I needed to
do), is include the Target attribute (ie. when a hyperlink is set to open in
a new window, I need the "Target="_blank" to be included in the <a href>
tag.
So, if I have a hyperlink in Word that is supposed to open the page in a new
browser window, I need to wrap that text with:
<a href="www.whatever.com" target='_blank">This is the hyperlink</a>
Some hyperlinks are supposed to open in a new window, and some are not.
Can someone help me incorporate this particular requirement into the
following code (which currently works great except for not using the target
attribute):
Sub demo()
Dim nLink As Long
Dim hLink As Hyperlink
Dim strText As String
Dim oRg As Range
Const qt = """"
For nLink = ActiveDocument.Hyperlinks.Count To 1 Step -1
Set hLink = ActiveDocument.Hyperlinks(nLink)
Set oRg = hLink.Range
strText = "<a href=" & qt & hLink.Address
If hLink.SubAddress <> "" Then
strText = strText & "#" & hLink.SubAddress
End If
strText = strText & qt & ">" & _
hLink.TextToDisplay & "</a>"
oRg.Text = strText
Next
End Sub
Thanks for any help on this, and for taking the time.