Why my google search macro is returning error 424 - Object required?












0















I have this simple macro that opens up IE and type a word in search box. It was working before, but now is returning




Error 424 - Object required.




Any ideas on what is happening? Is there any lib reference that I'm missing?



Sub AcessaPaginaDados()
Dim xobj As HTMLDivElement
Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate ("https://www.google.com/")

Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop

Set xobj = ie.document.getElementById("lst-ib")
Call xobj.setAttribute("value", "teste")
End Sub









share|improve this question

























  • What line errors? Is it copied code missing the HTML references used for xobj do you have a new version of web browser? Has something changed in the environment since?

    – Nathan_Sav
    Nov 22 '18 at 13:56











  • On which line is error?

    – QHarr
    Nov 22 '18 at 13:56











  • you need to remove the parenthesis here ie.Navigate ("https://www.google.com/")

    – Pᴇʜ
    Nov 22 '18 at 14:03











  • Actually this is part of a big search and fill vba and I find this piece with error. The error line is the Set xobj = ie.document.getElementById("lst-ib")

    – Rafael Torres
    Nov 22 '18 at 14:11











  • Removed the parenthesis and used the [title=Pesquisar] solution and it worked. Thank you

    – Rafael Torres
    Nov 22 '18 at 16:10
















0















I have this simple macro that opens up IE and type a word in search box. It was working before, but now is returning




Error 424 - Object required.




Any ideas on what is happening? Is there any lib reference that I'm missing?



Sub AcessaPaginaDados()
Dim xobj As HTMLDivElement
Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate ("https://www.google.com/")

Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop

Set xobj = ie.document.getElementById("lst-ib")
Call xobj.setAttribute("value", "teste")
End Sub









share|improve this question

























  • What line errors? Is it copied code missing the HTML references used for xobj do you have a new version of web browser? Has something changed in the environment since?

    – Nathan_Sav
    Nov 22 '18 at 13:56











  • On which line is error?

    – QHarr
    Nov 22 '18 at 13:56











  • you need to remove the parenthesis here ie.Navigate ("https://www.google.com/")

    – Pᴇʜ
    Nov 22 '18 at 14:03











  • Actually this is part of a big search and fill vba and I find this piece with error. The error line is the Set xobj = ie.document.getElementById("lst-ib")

    – Rafael Torres
    Nov 22 '18 at 14:11











  • Removed the parenthesis and used the [title=Pesquisar] solution and it worked. Thank you

    – Rafael Torres
    Nov 22 '18 at 16:10














0












0








0








I have this simple macro that opens up IE and type a word in search box. It was working before, but now is returning




Error 424 - Object required.




Any ideas on what is happening? Is there any lib reference that I'm missing?



Sub AcessaPaginaDados()
Dim xobj As HTMLDivElement
Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate ("https://www.google.com/")

Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop

Set xobj = ie.document.getElementById("lst-ib")
Call xobj.setAttribute("value", "teste")
End Sub









share|improve this question
















I have this simple macro that opens up IE and type a word in search box. It was working before, but now is returning




Error 424 - Object required.




Any ideas on what is happening? Is there any lib reference that I'm missing?



Sub AcessaPaginaDados()
Dim xobj As HTMLDivElement
Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate ("https://www.google.com/")

Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop

Set xobj = ie.document.getElementById("lst-ib")
Call xobj.setAttribute("value", "teste")
End Sub






html excel vba excel-vba web-scraping






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 14:11









QHarr

34.1k82044




34.1k82044










asked Nov 22 '18 at 13:52









Rafael TorresRafael Torres

175




175













  • What line errors? Is it copied code missing the HTML references used for xobj do you have a new version of web browser? Has something changed in the environment since?

    – Nathan_Sav
    Nov 22 '18 at 13:56











  • On which line is error?

    – QHarr
    Nov 22 '18 at 13:56











  • you need to remove the parenthesis here ie.Navigate ("https://www.google.com/")

    – Pᴇʜ
    Nov 22 '18 at 14:03











  • Actually this is part of a big search and fill vba and I find this piece with error. The error line is the Set xobj = ie.document.getElementById("lst-ib")

    – Rafael Torres
    Nov 22 '18 at 14:11











  • Removed the parenthesis and used the [title=Pesquisar] solution and it worked. Thank you

    – Rafael Torres
    Nov 22 '18 at 16:10



















  • What line errors? Is it copied code missing the HTML references used for xobj do you have a new version of web browser? Has something changed in the environment since?

    – Nathan_Sav
    Nov 22 '18 at 13:56











  • On which line is error?

    – QHarr
    Nov 22 '18 at 13:56











  • you need to remove the parenthesis here ie.Navigate ("https://www.google.com/")

    – Pᴇʜ
    Nov 22 '18 at 14:03











  • Actually this is part of a big search and fill vba and I find this piece with error. The error line is the Set xobj = ie.document.getElementById("lst-ib")

    – Rafael Torres
    Nov 22 '18 at 14:11











  • Removed the parenthesis and used the [title=Pesquisar] solution and it worked. Thank you

    – Rafael Torres
    Nov 22 '18 at 16:10

















What line errors? Is it copied code missing the HTML references used for xobj do you have a new version of web browser? Has something changed in the environment since?

– Nathan_Sav
Nov 22 '18 at 13:56





What line errors? Is it copied code missing the HTML references used for xobj do you have a new version of web browser? Has something changed in the environment since?

– Nathan_Sav
Nov 22 '18 at 13:56













On which line is error?

– QHarr
Nov 22 '18 at 13:56





On which line is error?

– QHarr
Nov 22 '18 at 13:56













you need to remove the parenthesis here ie.Navigate ("https://www.google.com/")

– Pᴇʜ
Nov 22 '18 at 14:03





you need to remove the parenthesis here ie.Navigate ("https://www.google.com/")

– Pᴇʜ
Nov 22 '18 at 14:03













Actually this is part of a big search and fill vba and I find this piece with error. The error line is the Set xobj = ie.document.getElementById("lst-ib")

– Rafael Torres
Nov 22 '18 at 14:11





Actually this is part of a big search and fill vba and I find this piece with error. The error line is the Set xobj = ie.document.getElementById("lst-ib")

– Rafael Torres
Nov 22 '18 at 14:11













Removed the parenthesis and used the [title=Pesquisar] solution and it worked. Thank you

– Rafael Torres
Nov 22 '18 at 16:10





Removed the parenthesis and used the [title=Pesquisar] solution and it worked. Thank you

– Rafael Torres
Nov 22 '18 at 16:10












1 Answer
1






active

oldest

votes


















1














That id doesn't appear against the input box when I open google. You can use an attribute = value selector to target the title attribute of the search box. Right-click inspect the search box and see what your local language attribute value is for title=. In U.K. the value is Search. Use whatever your local value is.



Element html:



enter image description here



Other:



Also, .navigate2 is the preferred method.



If the page is slow loading you may need a loop until element present.



Option Explicit

Public Sub AcessaPaginaDados()
Dim xobj As HTMLDivElement

With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate2 "https://www.google.com/"

While .Busy Or .readyState < 4: DoEvents: Wend

Set xobj = .document.querySelector("[title=Search]")
xobj.Value = "teste"

Stop
.Quit
End With

End Sub





share|improve this answer


























  • Tried your code and got the same error on Set xobj = .document.querySelector("[title=Search]")

    – Rafael Torres
    Nov 22 '18 at 14:12











  • Did you check what your html gives as the title attribute value? If it doesn't say Search and says something like Buscar then you need to change to [title=Buscar]

    – QHarr
    Nov 22 '18 at 14:13













  • If the page is slow loading you may need a loop until element present. If you can confirm what the title value is for the attribute and that it still doesn't work I will add loop code in above.

    – QHarr
    Nov 22 '18 at 14:16






  • 1





    Thank you everyone! @QHarr I updated the code with your solution and it worked like a charm. My local value was [title=Pesquisar]

    – Rafael Torres
    Nov 22 '18 at 16:08













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432490%2fwhy-my-google-search-macro-is-returning-error-424-object-required%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














That id doesn't appear against the input box when I open google. You can use an attribute = value selector to target the title attribute of the search box. Right-click inspect the search box and see what your local language attribute value is for title=. In U.K. the value is Search. Use whatever your local value is.



Element html:



enter image description here



Other:



Also, .navigate2 is the preferred method.



If the page is slow loading you may need a loop until element present.



Option Explicit

Public Sub AcessaPaginaDados()
Dim xobj As HTMLDivElement

With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate2 "https://www.google.com/"

While .Busy Or .readyState < 4: DoEvents: Wend

Set xobj = .document.querySelector("[title=Search]")
xobj.Value = "teste"

Stop
.Quit
End With

End Sub





share|improve this answer


























  • Tried your code and got the same error on Set xobj = .document.querySelector("[title=Search]")

    – Rafael Torres
    Nov 22 '18 at 14:12











  • Did you check what your html gives as the title attribute value? If it doesn't say Search and says something like Buscar then you need to change to [title=Buscar]

    – QHarr
    Nov 22 '18 at 14:13













  • If the page is slow loading you may need a loop until element present. If you can confirm what the title value is for the attribute and that it still doesn't work I will add loop code in above.

    – QHarr
    Nov 22 '18 at 14:16






  • 1





    Thank you everyone! @QHarr I updated the code with your solution and it worked like a charm. My local value was [title=Pesquisar]

    – Rafael Torres
    Nov 22 '18 at 16:08


















1














That id doesn't appear against the input box when I open google. You can use an attribute = value selector to target the title attribute of the search box. Right-click inspect the search box and see what your local language attribute value is for title=. In U.K. the value is Search. Use whatever your local value is.



Element html:



enter image description here



Other:



Also, .navigate2 is the preferred method.



If the page is slow loading you may need a loop until element present.



Option Explicit

Public Sub AcessaPaginaDados()
Dim xobj As HTMLDivElement

With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate2 "https://www.google.com/"

While .Busy Or .readyState < 4: DoEvents: Wend

Set xobj = .document.querySelector("[title=Search]")
xobj.Value = "teste"

Stop
.Quit
End With

End Sub





share|improve this answer


























  • Tried your code and got the same error on Set xobj = .document.querySelector("[title=Search]")

    – Rafael Torres
    Nov 22 '18 at 14:12











  • Did you check what your html gives as the title attribute value? If it doesn't say Search and says something like Buscar then you need to change to [title=Buscar]

    – QHarr
    Nov 22 '18 at 14:13













  • If the page is slow loading you may need a loop until element present. If you can confirm what the title value is for the attribute and that it still doesn't work I will add loop code in above.

    – QHarr
    Nov 22 '18 at 14:16






  • 1





    Thank you everyone! @QHarr I updated the code with your solution and it worked like a charm. My local value was [title=Pesquisar]

    – Rafael Torres
    Nov 22 '18 at 16:08
















1












1








1







That id doesn't appear against the input box when I open google. You can use an attribute = value selector to target the title attribute of the search box. Right-click inspect the search box and see what your local language attribute value is for title=. In U.K. the value is Search. Use whatever your local value is.



Element html:



enter image description here



Other:



Also, .navigate2 is the preferred method.



If the page is slow loading you may need a loop until element present.



Option Explicit

Public Sub AcessaPaginaDados()
Dim xobj As HTMLDivElement

With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate2 "https://www.google.com/"

While .Busy Or .readyState < 4: DoEvents: Wend

Set xobj = .document.querySelector("[title=Search]")
xobj.Value = "teste"

Stop
.Quit
End With

End Sub





share|improve this answer















That id doesn't appear against the input box when I open google. You can use an attribute = value selector to target the title attribute of the search box. Right-click inspect the search box and see what your local language attribute value is for title=. In U.K. the value is Search. Use whatever your local value is.



Element html:



enter image description here



Other:



Also, .navigate2 is the preferred method.



If the page is slow loading you may need a loop until element present.



Option Explicit

Public Sub AcessaPaginaDados()
Dim xobj As HTMLDivElement

With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate2 "https://www.google.com/"

While .Busy Or .readyState < 4: DoEvents: Wend

Set xobj = .document.querySelector("[title=Search]")
xobj.Value = "teste"

Stop
.Quit
End With

End Sub






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 14:15

























answered Nov 22 '18 at 14:01









QHarrQHarr

34.1k82044




34.1k82044













  • Tried your code and got the same error on Set xobj = .document.querySelector("[title=Search]")

    – Rafael Torres
    Nov 22 '18 at 14:12











  • Did you check what your html gives as the title attribute value? If it doesn't say Search and says something like Buscar then you need to change to [title=Buscar]

    – QHarr
    Nov 22 '18 at 14:13













  • If the page is slow loading you may need a loop until element present. If you can confirm what the title value is for the attribute and that it still doesn't work I will add loop code in above.

    – QHarr
    Nov 22 '18 at 14:16






  • 1





    Thank you everyone! @QHarr I updated the code with your solution and it worked like a charm. My local value was [title=Pesquisar]

    – Rafael Torres
    Nov 22 '18 at 16:08





















  • Tried your code and got the same error on Set xobj = .document.querySelector("[title=Search]")

    – Rafael Torres
    Nov 22 '18 at 14:12











  • Did you check what your html gives as the title attribute value? If it doesn't say Search and says something like Buscar then you need to change to [title=Buscar]

    – QHarr
    Nov 22 '18 at 14:13













  • If the page is slow loading you may need a loop until element present. If you can confirm what the title value is for the attribute and that it still doesn't work I will add loop code in above.

    – QHarr
    Nov 22 '18 at 14:16






  • 1





    Thank you everyone! @QHarr I updated the code with your solution and it worked like a charm. My local value was [title=Pesquisar]

    – Rafael Torres
    Nov 22 '18 at 16:08



















Tried your code and got the same error on Set xobj = .document.querySelector("[title=Search]")

– Rafael Torres
Nov 22 '18 at 14:12





Tried your code and got the same error on Set xobj = .document.querySelector("[title=Search]")

– Rafael Torres
Nov 22 '18 at 14:12













Did you check what your html gives as the title attribute value? If it doesn't say Search and says something like Buscar then you need to change to [title=Buscar]

– QHarr
Nov 22 '18 at 14:13







Did you check what your html gives as the title attribute value? If it doesn't say Search and says something like Buscar then you need to change to [title=Buscar]

– QHarr
Nov 22 '18 at 14:13















If the page is slow loading you may need a loop until element present. If you can confirm what the title value is for the attribute and that it still doesn't work I will add loop code in above.

– QHarr
Nov 22 '18 at 14:16





If the page is slow loading you may need a loop until element present. If you can confirm what the title value is for the attribute and that it still doesn't work I will add loop code in above.

– QHarr
Nov 22 '18 at 14:16




1




1





Thank you everyone! @QHarr I updated the code with your solution and it worked like a charm. My local value was [title=Pesquisar]

– Rafael Torres
Nov 22 '18 at 16:08







Thank you everyone! @QHarr I updated the code with your solution and it worked like a charm. My local value was [title=Pesquisar]

– Rafael Torres
Nov 22 '18 at 16:08






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432490%2fwhy-my-google-search-macro-is-returning-error-424-object-required%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith