Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 12-23-2019, 12:40 PM
macropod's Avatar
macropod macropod is offline Convert html links into embedded hyperlinks Windows 7 64bit Convert html links into embedded hyperlinks Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by noslenwerd View Post
It seems that code isn't able to handle the quotation marks around the link.Would it be possible for me to modify the code so it can handle the quotation marks?
The code does handle quotes, but expects them to be straight quotes, not smart quotes. Smart quotes are not valid in such strings anyway. Still, if that's what you've got, you could change:
Quote:
StrAddr = Replace(Split(Split(.Text, ">")(0), "=")(1), Chr(34), "")
to:


Quote:
StrAddr = Replace(Replace(Replace(Split(Split(.Text, ">")(0), "=")(1), Chr(34), ""), Chr(147), ""), Chr(148), "")
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #17  
Old 12-23-2019, 01:41 PM
noslenwerd noslenwerd is offline Convert html links into embedded hyperlinks Windows 10 Convert html links into embedded hyperlinks Office 2016 for Mac
Novice
 
Join Date: Dec 2019
Posts: 15
noslenwerd is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
The code does handle quotes, but expects them to be straight quotes, not smart quotes. Smart quotes are not valid in such strings anyway. Still, if that's what you've got, you could change:

to:
Ahhh great point. I am using sublime text to edit my code, and looks like they use smart quote instead.

Thank you as always.
Reply With Quote
  #18  
Old 12-23-2019, 02:49 PM
noslenwerd noslenwerd is offline Convert html links into embedded hyperlinks Windows 10 Convert html links into embedded hyperlinks Office 2016 for Mac
Novice
 
Join Date: Dec 2019
Posts: 15
noslenwerd is on a distinguished road
Default

Sorry for the additional bump.

Would you mind explaining what this line of code means exactly? I am writing a similar macro that will take img html, and insert an image.

If you would be able to pull this apart, I do think I can handle the image insertion myself

Code:
	    .Text = "\<[Aa] href=([!\>]@)\>([!\<]@)\</a\>"
Reply With Quote
  #19  
Old 12-23-2019, 02:53 PM
macropod's Avatar
macropod macropod is offline Convert html links into embedded hyperlinks Windows 7 64bit Convert html links into embedded hyperlinks Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

That's a Word wildcard Find expression. See: Finding and replacing characters using wildcards

It appears you're hijacking this thread for a different topic. Start new topics in new threads. And no, it won't help with the image insertion you've discussed at: VBA to insert image in current directory regardless of image type | VBA Express
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #20  
Old 12-23-2019, 02:58 PM
noslenwerd noslenwerd is offline Convert html links into embedded hyperlinks Windows 10 Convert html links into embedded hyperlinks Office 2016 for Mac
Novice
 
Join Date: Dec 2019
Posts: 15
noslenwerd is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
That's a Word wildcard Find expression. See: Finding and replacing characters using wildcards

It appears you're hijacking this thread for a different topic. Start new topics in new threads. And no, it won't help with the image insertion you've discussed at: VBA to insert image in current directory regardless of image type | VBA Express
Sorry I didn't want to clutter up the forum unnecessarily. I will make a new post next time.

The request from this thread is actually different from the one on the VBAX forum.

Either way thank you again for your help.
Reply With Quote
  #21  
Old 01-31-2020, 08:54 AM
noslenwerd noslenwerd is offline Convert html links into embedded hyperlinks Windows 10 Convert html links into embedded hyperlinks Office 2016 for Mac
Novice
 
Join Date: Dec 2019
Posts: 15
noslenwerd is on a distinguished road
Default

macropod... thank you again for your help thus far.

The code you helped with, which is below, strips out the bolded URL in the link format in my WordDoc.

For instance it starts as this:
<a href="https://developers.google.com/speed/pagespeed/insights/?url=websiteurl.com">PageSpeed Insights</a>
And ends up linking to this (strips everything after the =):
PageSpeed Insights

Code:
Sub ConvertLinks()
Dim StrAddr As String, StrDisp As String
' Turn Off Screen Updating
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .Text = "\<[Aa] href=([!\>]@)\>([!\<]@)\</a\>"
    .ClearFormatting
    .Replacement.ClearFormatting
    .Replacement.Text = ""
    .Forward = True
    .MatchWildcards = True
    .Wrap = wdFindStop
    .Execute
  End With
  Do While .Find.Found = True
    StrAddr = Replace(Replace(Replace(Split(Split(.Text, ">")(0), "=")(1), Chr(34), ""), Chr(147), ""), Chr(148), "")
    StrDisp = Split(Split(.Text, ">")(1), "<")(0)
    .Hyperlinks.Add Anchor:=.Duplicate, _
      Address:=StrAddr, TextToDisplay:=StrDisp
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
' Restore Screen Updating
Application.ScreenUpdating = True
End Sub
Reply With Quote
  #22  
Old 01-31-2020, 02:57 PM
macropod's Avatar
macropod macropod is offline Convert html links into embedded hyperlinks Windows 7 64bit Convert html links into embedded hyperlinks Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Well, what you have with:
<a href="https://developers.google.com/speed/pagespeed/insights/?url=websiteurl.com">PageSpeed Insights</a>
is a link though google to websiteurl.com, whereas you really should have:
<a href="https://websiteurl.com">PageSpeed Insights</a>
That said, you can resolve the matter by changing:
"="
in the VBA code to:
"href="
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #23  
Old 02-04-2020, 07:44 AM
noslenwerd noslenwerd is offline Convert html links into embedded hyperlinks Windows 10 Convert html links into embedded hyperlinks Office 2016 for Mac
Novice
 
Join Date: Dec 2019
Posts: 15
noslenwerd is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Well, what you have with:
<a href="https://developers.google.com/speed/pagespeed/insights/?url=websiteurl.com">PageSpeed Insights</a>
is a link though google to websiteurl.com, whereas you really should have:
<a href="https://websiteurl.com">PageSpeed Insights</a>
That said, you can resolve the matter by changing:
"="
in the VBA code to:
"href="
Actually, that link to google is appending the website, and running a page speed report on websiteurl.com.

Thanks for the reply, but looks like href= is already in the code I posted above?


Code:
With ActiveDocument.Range
  With .Find
    .Text = "\<[Aa] href=([!\>]@)\>([!\<]@)\</a\>"
Reply With Quote
  #24  
Old 02-04-2020, 02:00 PM
macropod's Avatar
macropod macropod is offline Convert html links into embedded hyperlinks Windows 7 64bit Convert html links into embedded hyperlinks Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

There is a "=" in the VBA code...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
a href, hyperlink, macro

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert html links into embedded hyperlinks Embedded links spheon Word 1 06-07-2011 04:11 PM
convert html to text at opening etfjr Word 0 12-13-2010 11:14 AM
Can you actually write HTML and CSS in a word document and send it as an html page jackaroo Word 0 07-12-2010 07:49 AM
Word with frames, table of contents, and hyperlinks to html NHMC Word 0 12-09-2009 12:54 PM
Convert a file from HTML to WORD format weblayout view gtselvam Word 0 12-02-2008 03:53 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:56 PM.


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