Home > Software engineering >  Open a webpage with vba and click on the "active directory" button so you can log in
Open a webpage with vba and click on the "active directory" button so you can log in

Time:03-15

so I want to open a web page directly from excel vba where I need to click on the "active directory" button which has no ID, this button uses the windows credentials to automatically log so I just need to click there to later once I´m logged I can start populating some fields. This generic code is giving me an error message " The object invoked has disconnected from its clients" I assume it´s related to the web page secure log on. Thanks in advance for any help that can be provided.

Sub test() Const sSiteName = "https://www.padb.ford.com/PadbStrutsWeb/treeHomePre.do" Dim oIE As Object Dim oHDoc As HTMLDocument

Set oIE = CreateObject("InternetExplorer.Application")

With oIE
    .Visible = True
    .navigate sSiteName
End With

While oIE.readyState <> 4
    DoEvents
Wend

Set oHDoc = oIE.document

With oHDoc

'Here I want to click on that button so I can latter populate some of the fields, once page is loaded'

End With

End Sub

CodePudding user response:

IE is EOL and shouldn't be used anymore.

I can't tell you how exactly on the page the button is clicked, because that requires the HTML code. But the disconnection from the client may be due to the way IE is initialized. Try it via the GUID D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E

Sub test()
  Const sSiteName = "https://www.padb.ford.com/PadbStrutsWeb/treeHomePre.do"
  Dim oIE As Object
  Dim oHDoc As HTMLDocument
  
  Set oIE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
  
  With oIE
    .Visible = True
    .navigate sSiteName
  End With
  
  While oIE.readyState <> 4
    DoEvents
  Wend
  
  Set oHDoc = oIE.document
  
  With oHDoc
    'Here I want to click on that button so I can latter populate some of the fields, once page is loaded'
  End With
End Sub
  • Related