Macro eror help ?

%3CLINGO-SUB%20id%3D%22lingo-sub-2435161%22%20slang%3D%22en-US%22%3EMacro%20eror%20help%20%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2435161%22%20slang%3D%22en-US%22%3E%3CP%3ECan%20u%20help%20me%20to%20fix%20these%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E'Google%20Search%20using%20VBA%3CBR%20%2F%3ESub%20SearchGoogle()%3CBR%20%2F%3EDim%20objIE%20As%20Object%3CBR%20%2F%3EDim%20lngMaxRows%20As%20Long%3CBR%20%2F%3EDim%20lngCtr%20As%20Long%3CBR%20%2F%3EDim%20strSearchValue%20As%20String%3CBR%20%2F%3EDim%20objResults%20As%20Object%3CBR%20%2F%3E%3CBR%20%2F%3E'Get%20the%20Maximum%20number%20of%20rows%20in%20Col%20A%2C%20that%20has%20data%3CBR%20%2F%3ElngMaxRows%20%3D%20Cells(Rows.Count%2C%201).End(xlUp).Row%3CBR%20%2F%3E%3CBR%20%2F%3E'Loop%20through%20till%20the%20maximum%20row%20and%20search%20for%20the%20value%20in%20each%20row%3CBR%20%2F%3EFor%20lngCtr%20%3D%202%20To%20lngMaxRows%3CBR%20%2F%3E%3CBR%20%2F%3ESet%20objIE%20%3D%20CreateObject(%22InternetExplorer.Application%22)%3CBR%20%2F%3E%3CBR%20%2F%3E'Get%20the%20search%20value%20from%20the%20current%20row%20in%20Column%20A%3CBR%20%2F%3EstrSearchValue%20%3D%20Cells(lngCtr%2C%201).Value%3CBR%20%2F%3E%3CBR%20%2F%3EApplication.StatusBar%20%3D%20%22Searching%20for%20keyword%3A%20'%22%20%26amp%3Bamp%3B%20_%3CBR%20%2F%3EstrSearchValue%20%26amp%3Bamp%3B%20%22'%22%3CBR%20%2F%3E%3CBR%20%2F%3EWith%20objIE%3CBR%20%2F%3E'Keep%20the%20Internet%20Explorer%20Closed.%3CBR%20%2F%3E'Set%20.Visible%20%3D%20True%2C%20if%20you%20want%20IE%20to%20remain%20opened.%3CBR%20%2F%3E.Visible%20%3D%20False%3CBR%20%2F%3E%3CBR%20%2F%3E'Navigate%20to%20the%20search%20value%3CBR%20%2F%3E.navigate%20%22%3CA%20href%3D%22http%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3D%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttp%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3D%3C%2FA%3E%22%20%26amp%3Bamp%3B%20strSearchValue%3CBR%20%2F%3E%3CBR%20%2F%3E'Wait%20some%20to%20time%20for%20loading%20the%20page%3CBR%20%2F%3EWhile%20.Busy%3CBR%20%2F%3EDoEvents%3CBR%20%2F%3EWend%3CBR%20%2F%3E%3CBR%20%2F%3E'Wait%20for%20another%202%20seconds%2C%20just%20in%20case%20the%20page%20hasn't%20yet%20loaded%3CBR%20%2F%3EApplication.Wait%20(Now%20%2B%20TimeValue(%220%3A00%3A02%22))%3CBR%20%2F%3E%3CBR%20%2F%3E'Get%20the%20search%20results%3CBR%20%2F%3ESet%20objResults%20%3D%20.document.getElementById(%22resultStats%22)%3CBR%20%2F%3E%3CBR%20%2F%3E'Fill%20up%20the%20corresponding%20Search%20Result%20column%3CBR%20%2F%3ECells(lngCtr%2C%202).Value%20%3D%20objResults.innerText%3CBR%20%2F%3E%3CBR%20%2F%3E'Close%20the%20Internet%20Explorer%3CBR%20%2F%3E.Quit%3CBR%20%2F%3EEnd%20With%3CBR%20%2F%3E%3CBR%20%2F%3E'Destroy%20the%20object%3CBR%20%2F%3ESet%20objIE%20%3D%20Nothing%3CBR%20%2F%3ENext%20lngCtr%3CBR%20%2F%3E%3CBR%20%2F%3EApplication.StatusBar%20%3D%20False%3CBR%20%2F%3E%3CBR%20%2F%3E'Display%20message%2C%20when%20complete%3CBR%20%2F%3EMsgBox%20%22Google%20Search%20Complete!!!%22%3CBR%20%2F%3EEnd%20Sub%5C%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2435161%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Visitor

Can u help me to fix these 

 

'Google Search using VBA
Sub SearchGoogle()
Dim objIE As Object
Dim lngMaxRows As Long
Dim lngCtr As Long
Dim strSearchValue As String
Dim objResults As Object

'Get the Maximum number of rows in Col A, that has data
lngMaxRows = Cells(Rows.Count, 1).End(xlUp).Row

'Loop through till the maximum row and search for the value in each row
For lngCtr = 2 To lngMaxRows

Set objIE = CreateObject("InternetExplorer.Application")

'Get the search value from the current row in Column A
strSearchValue = Cells(lngCtr, 1).Value

Application.StatusBar = "Searching for keyword: '" & _
strSearchValue & "'"

With objIE
'Keep the Internet Explorer Closed.
'Set .Visible = True, if you want IE to remain opened.
.Visible = False

'Navigate to the search value
.navigate "http://www.google.com/search?q=" & strSearchValue

'Wait some to time for loading the page
While .Busy
DoEvents
Wend

'Wait for another 2 seconds, just in case the page hasn't yet loaded
Application.Wait (Now + TimeValue("0:00:02"))

'Get the search results
Set objResults = .document.getElementById("resultStats")

'Fill up the corresponding Search Result column
Cells(lngCtr, 2).Value = objResults.innerText

'Close the Internet Explorer
.Quit
End With

'Destroy the object
Set objIE = Nothing
Next lngCtr

Application.StatusBar = False

'Display message, when complete
MsgBox "Google Search Complete!!!"
End Sub\

0 Replies