I have a problem with this code. I have to make a macro that detects the most repeated words in a domain for example cats
is repeated 1180 times in the domain www.love_cats.com
(example). I plan to do it with the google API that counts the total results as in the image
The code that I have is.
Sub diccionarios()
screenUpdateStatus = Application.ScreenUpdating
statusBarStatus = Application.DisplayStatusBar
calcStatus = Application.Calculation
eventsStatus = Application.EnableEvents
displayPageBreakStatus = ActiveSheet.DisplayPageBreaks
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Application.DisplayAlerts = True
Dim dicc As New Scripting.Dictionary
Dim columnaSalida As Integer, k As Variant, filaSalida As Long,
grantotalPalabras As Long
Dim palabra As String, rango As Range, ultima As Variant, celda As Variant,
contador As Long
ultima = Sheets("Sheet1").Range("A1").End(xlDown).Row
Set rango = Range("A1:A" & ultima)
Set dicc = New Scripting.Dictionary
For Each celda In rango
palabra = celda
If Not dicc.Exists(palabra) Then
dicc.Item(palabra) = 1
Else
dicc.Item(palabra) = dicc.Item(palabra) + 1
End If
Next celda
filaSalida = 1
columnaSalida = 2
contador = 1
For Each k In dicc.Keys
Dim ie As Object, form As Variant, button As Variant, _
LR As Integer, var As String, var1 As Object
var = k & " site :www.domea.dk"
Set ie = CreateObject("internetexplorer.application")
ie.Visible = False
With ie
.Visible = False
.navigate "https://www.google.co.in/?gws_rd=ssl"
End With
Application.Wait (Now + TimeValue("0:00:02"))
ie.document.getElementById("lst-ib").Value = var
Set form = ie.document.getElementsByTagName("form")
Application.Wait (Now + TimeValue("0:00:02"))
Set button = form(0).onsubmit
form(0).submit
Application.Wait (Now + TimeValue("0:00:02"))
Set var1 = ie.document.getElementById("resultStats")
Cells(contador, 2).Value = var1.innerText
ie.Quit
Set ie = Nothing
contador = contador + 1
Next k
Set dicc = Nothing
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = screenUpdateState
Application.DisplayStatusBar = True
Application.Calculation = calcState
Application.EnableEvents = eventsState
ActiveSheet.DisplayPageBreaks = displayPageBreaksState
End Sub
Then it occurred to me to use a dictionary, where I put all the possible words (58 thousand words) and go through them, It count the words and the first 5 would be the ones that are shown. The problem is that the macro takes a long time (15 minutos), becomes saturated and fails.