Extracting email addresses from hyperlinks.

G

Guest

I copied several hundred email address hyperlinks from an html page into a
spreadsheet. They all showed text as "Click her to email" on the html page.
They copied correctly as hyperlink "mailto" links, but the text in the excel
field is still "Click her to email". The email links span A1 - A500. I am
trying to find a way to show the email address only in B1 - B500. How do i
do this?

Brossyg
 
D

Dave Peterson

Saved from a previous post:

Are the hyperlinks inserted via Insert|Hyperlink?

If yes:

You can use a User defined function to retrieve the link.

Option Explicit
Function GetURL(Rng As Range) As String
Application.Volatile

Set Rng = Rng(1)

If Rng.Hyperlinks.Count = 0 Then
GetURL = ""
Else
GetURL = Rng.Hyperlinks(1).Address
End If
End Function

So if you had a hyperlink in A1, you could put =getURL(a1) in that adjacent
cell.

Be aware that if you change the hyperlink, then this formula cell won't change
until your workbook calculates.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=getURL(a1)

=========
After you extract your email addresses, you could select that column B1:B500 and
edit|copy followed by edit|paste special values

Then edit|replace
what: mailto:
with: (leave blank)
replace all

or just use:
=mid(geturl(a1),8,255)
and leave it a formula.
 
G

Guest

Unfortunately, this returns #NAME?. No, the cells copied from the html page
were simply Select All/Copy on the html page (display page, not the code) and
then Pasted into the Excel sheet. The links work pefectly as links once in
the Excel sheet.

Also, if I highlight one and right click on Edit Hyperlink, all the info is
there correctly.

Any other possibilities?
 
D

Dave Peterson

I'm betting that you didn't put the code in a general module. Try following
those instructions once more.
 
G

Guest

Your awesome...thank you. I had put it in the sheet area...right clicking on
the sheet tab. It works now.

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top