Sharid
Well-known Member
- Joined
- Apr 22, 2007
- Messages
- 1,064
- Office Version
- 2016
- Platform
- Windows
Hi can somebody please help
Can this code be written better, so it processes the URL faster, it took almost 3 hours to process 1000 URL
What the code does
I have a url list in Sheet2 "URL LIST" which it uses to process and then puts result in Sheet1
Thanks for having a look
Can this code be written better, so it processes the URL faster, it took almost 3 hours to process 1000 URL
What the code does
I have a url list in Sheet2 "URL LIST" which it uses to process and then puts result in Sheet1
Code:
[COLOR=#ff0000]'Count url in sheet2[/COLOR]
With Worksheets("URL LIST")
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Sheets("URL LIST").Range("L1").Value = lastRow
End With
[COLOR=#ff0000]' Run main code[/COLOR]
Dim wb As Workbook
Dim x As Variant
Dim i, j, k, l As Integer
Dim r As Long, lr As Long
Dim wsSheet As Worksheet, links As Variant, ie As Object, link As Variant
Dim rw As Long
i = 2
k = 2
l = 2
[COLOR=#ff0000] 'SHEET2 as sheet with URL[/COLOR]
Set wb = ThisWorkbook
Set wsSheet = wb.Sheets("URL LIST")
[COLOR=#ff0000] 'Set IE = InternetExplorer[/COLOR]
Set ie = CreateObject("InternetExplorer.Application")
rw = wsSheet.Cells(wsSheet.Rows.Count, "A").End(xlUp).Row
links = wsSheet.Range("A1:A" & rw)
[COLOR=#ff0000] 'IE Open Time per page 5sec and check links on Sheet2 Column A[/COLOR]
With ie
.Visible = True
Application.Wait (Now + TimeValue("00:00:5"))
For Each link In links
.navigate (link)
While .Busy Or .readyState <> 4: DoEvents: Wend
Dim doc As HTMLDocument [COLOR=#ff0000]'variable for document or data which need to be extracted out of webpage[/COLOR]
Set doc = ie.document
Dim dd As Variant
On Error Resume Next
dd = doc.getElementsByClassName("[COLOR=#0000cd]PUT CLASS HERE[/COLOR]")(0).Children(0).href
On Error Resume Next
[COLOR=#ff0000]'Paste in this sheet[/COLOR]
Sheet1.Cells(Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row + 1, "A").Value = dd
[COLOR=#ff0000]'Deletes duplicates in column A Sheet1[/COLOR]
'Columns(1).RemoveDuplicates Columns:=Array(1)
[COLOR=#ff0000] ' Put no1 in sheet2 column F[/COLOR]
Sheets("URL LIST").Range("F" & Rows.Count).End(xlUp).Offset(1, 0).Value = 1
[COLOR=#ff0000] 'Count No1 in sheet2 Column F[/COLOR]
With Worksheets("URL LIST")
lastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
Sheets("URL LIST").Range("L2").Value = lastRow
End With
[COLOR=#ff0000]'Click CommandButton9 [/COLOR]
Call CommandButton9_Click
[COLOR=#ff0000]'navigate links[/COLOR]
Next link
[COLOR=#ff0000]'Close IE Browser[/COLOR]
.Quit
End With
Set ie = Nothing
Thanks for having a look