Home > Blockchain >  Open a webpage with VBA and click on the "active directory" button to log in
Open a webpage with VBA and click on the "active directory" button to log in

Time:06-11

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.

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