Forum

Extract all hyper U...
 
Notifications
Clear all

Extract all hyper URLS

6 Posts
2 Users
0 Reactions
63 Views
(@marsil)
Posts: 72
Estimable Member
Topic starter
 

Hi,

Could you please help me.

I have a sit of URLs and I want to extract all hyper URLS from each one.

Input: one column contain some URLs   >> Column A

Output: Two columns  >>>> Column C and D

Please check attached sample.

Thanks;

Marsil 

 
Posted : 21/11/2019 10:21 am
(@catalinb)
Posts: 1937
Member Admin
 

H Marsil,

You can try this basic code (you need to add references to Microsoft HTML Object Library and Microsoft Internet Controls):

Sub GetLink()
Dim IE As New InternetExplorer
Dim str As String, i As Long, j As Long
Dim Doc As HTMLDocument
Dim tagElements As Object
Dim element As HTMLObjectElement

i = 2
j = 2
Do Until ActiveSheet.Cells(j, 1) = ""
str = ActiveSheet.Cells(j, 1)
IE.navigate str
IE.Visible = True
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Set Doc = IE.document
Set tagElements = Doc.all.tags("a")

For Each element In tagElements
ActiveSheet.Cells(i, 3) = str
ActiveSheet.Cells(i, 4) = element.href
i = i + 1
Next element
j = j + 1
Loop

IE.Quit
End Sub

 
Posted : 24/11/2019 6:56 am
(@marsil)
Posts: 72
Estimable Member
Topic starter
 

Thanks Catalin.

 

I still need your help as still face an issue when i run the macro, please can u update the code in attached macro and resend me.

 

Thanks again for your time.

Marsil

 
Posted : 24/11/2019 12:08 pm
(@catalinb)
Posts: 1937
Member Admin
 

Just sending the file without saying what the problem is, is not at all useful. It's like saying "Houston, we have a problem..."

The code works, read again the instructions. Once you add the references, will work. If you don't know how to add a reference, go to visual basic editor-Tools-References and browse for those 2 libraries mentioned.

Catalin Bombea said
you need to add references to Microsoft HTML Object Library and Microsoft Internet Controls):

 
Posted : 24/11/2019 10:56 pm
(@marsil)
Posts: 72
Estimable Member
Topic starter
 

Hi Catalin,

Wow thanks so much Catalin for your help, this works great!!!

Could you please update the code to remove the duplication from file after the macro finish.

Thanks again for your time.

Marsil

 
Posted : 26/11/2019 5:30 am
(@catalinb)
Posts: 1937
Member Admin
 

I suggest recording a macro while removing duplicates manually, you will be able to reuse it and call it from the code provided, after the loop.

 
Posted : 26/11/2019 7:20 am
Share: