0

I tried to automate some logins and copy paste from the web onto my own machine. When I try the same thing from company's intranet I face problems. My error message is:

Object variable or With block variable not set.

Here is my code:

Sub getdata()
Dim IE As Object
Dim Doc As HTMLDocument
Dim naziv, test, test2 As Variant

'Set IE = CreateObject("InternetExplorer.Application")
Set IE = New InternetExplorerMedium

IE.Visible = True

IE.navigate "https://example.com/Pages/default.aspx"

Do While IE.readyState = 4
DoEvents
Loop

Set test = Doc
Set test2 = Doc

test2 = test.getElementById("testid")

MsgBox (test2.innerText)

End Sub
1
  • You have not initialized your Doc variable. Commented Jun 2, 2017 at 14:34

1 Answer 1

3

Remove the following two lines

Set test = Doc
Set test2 = Doc

Set the doc variable first

Set Doc = IE.document

and then set the test2 object

set test2 = Doc.getElementById("testid")
Sign up to request clarification or add additional context in comments.

5 Comments

'--> Set test2 = Doc.getElementById("testid") :)
@SiddharthRout Thanks for the correction. I forgot to add that. :)
++ no worries, I also miss small things sometime :)
Thanks once again. :)
Thank you very much for your quick help, now I am getting another error message: Method 'Document' of object 'IWebBrowser2' failed. I cannot imagine how can I solve that, I am trying it 1 week ago...thank you if you cam add some concerns :).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.