0

This code was able to run on my home laptop but not my work laptop.

Sub Autologin()
    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate "my_url"
    IE.Document.GetElementByID("j_username").Value = "my_username"`

The error occurs on the last line.

Run-time error '-2147417848 (80010108)':
Automation error, The object invoked has disconnected from its client.

Community
  • 1
  • 1
darrenvba
  • 201
  • 2
  • 5
  • 21
  • It sounds a little bit naive but do you have Internet Explorer installed on your work laptop? – RCaetano Oct 25 '16 at 12:21
  • Yes. The url opens fine on internet explorer but it doesn't input anything in the username box and the error message appears. Thanks – darrenvba Oct 25 '16 at 12:24
  • This maybe because of my lack of knowledge but are you trying to `GetElementByID` and assigning a value to it? it thought `GetElementByID` returned an object? how can it be assigned a value? Also then you are not capturing what is being returned? – Zac Oct 25 '16 at 12:42
  • Can you open other URLs with the same code (i.e. www.google.com)? If so, I'd try running Excel as administrator and see if it works that way. Cursory searching points to an IE permissions issue. – Comintern Oct 25 '16 at 12:43
  • Thanks Comintern. I didn't expect that but it isn't opening most other urls. Running as administrator doesn't seem to make a difference. Thanks Zac, I'm not certain but from looking at other similar scripts, the method above of = "my username" works, this exact code works on my home laptop too. – darrenvba Oct 25 '16 at 12:58
  • Just realised that it would work because you are calling for the element and then assigning a value to the ID of that element. Not sure if this would make much difference but have you tried referencing IE in your project rather than creating an `InternetExplorer.Application`? – Zac Oct 25 '16 at 14:53
  • Take a look at [this answer](http://stackoverflow.com/a/23232573/2165759) – omegastripes Oct 25 '16 at 16:17

2 Answers2

0

Give this a go:

Dim mainDoc As HTMLDocument 
Set mainDoc = IE.document

'This Is the where you add the id Name of the control you want To Access. You can find the id Name by searching through the source via ‘View – Source’ In Internet Explorer.

mainDoc.all("j_username").value="my_username"

Set IE = Nothing
Set mainDoc = Nothing
GeorgeP
  • 16
  • 1
-1

Give this a go:

Dim mainDoc As HTMLDocument
Set mainDoc = IE.document

'This Is the where you add the id Name of the control you want To Access. You can find the id Name by searching through the source via ‘View – Source’ In Internet Explorer.

mainDoc.all("j_username").value="my_username"

Set IE = Nothing
Set mainDoc = Nothing
GeorgeP
  • 16
  • 1