0

I'm having trouble getting the value from an input field called "due date"

Here is my HTML and VBA code.

I resolved error 462, but I can't retrieve certain data.

Actually I'm getting an error: Run-time error '91: Object variable or With block variable not set

VBA:

Sub Dane_z_www()

Range("A1").Clear

Dim appIE As InternetExplorerMedium
Dim my_url As String
Dim TerminPlatnosci As String
Dim shellWins As SHDocVw.ShellWindows
Dim IE As SHDocVw.InternetExplorer
Dim Doc As HTMLDocument

my_url = "https://example.com"
Set appIE = New InternetExplorerMedium

With appIE
.Visible = True
.Navigate my_url
End With

Set shellWins = New SHDocVw.ShellWindows

For Each IE In shellWins
    If IE.Name = "Internet Explorer" Then
        Set IEObject1 = IE
        Debug.Print IE.LocationURL
        Debug.Print IE.LocationName
End If
Next

Set shellWins = Nothing
Set IE = Nothing


Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop

Set Doc = appIE.Document

'TerminPlatnosci = Trim(Doc.getelementsByName("section-36-control$xf-771$xf-784$xml_termin_platnosci-control$xforms-input-1")(0).Value)
'TerminPlatnosci = Trim(Doc.getElementsByTagName("tr")(0).getElementsByName("input id")(0).getAttribute("value"))
TerminPlatnosci = Trim(Doc.querySelector("input[name='section-36-control$xf-771$xf-784$xml_termin_platnosci-control$xforms-input-1']").getAttribute("value"))
Range("A1").Value = TerminPlatnosci

appIE.Quit
Set appIE = Nothing

MsgBox "Daty zostały wczytane", , "Komunikat"

End Sub

HTML:

enter image description here

The code provides three variants that I used when trying to download the data.

  1. TerminPlatnosci = Trim(Doc.getelementsByName("section-36-control$xf-771$xf-784$xml_termin_platnosci-control$xforms-input-1")(0).Value)

  2. TerminPlatnosci = Trim(Doc.getElementsByTagName("tr")(0).getElementsByName("input id")(0).getAttribute("value"))

  3. TerminPlatnosci = Trim(Doc.querySelector("input[name='section-36-control$xf-771$xf-784$xml_termin_platnosci-control$xforms-input-1']").getAttribute("value"))

Range("A1").Value = TerminPlatnosci

4
  • Which line does it stop on when you get Object variable or With block variable not set? Commented Oct 10, 2023 at 19:05
  • Any code starting with TerminPlatnosci Commented Oct 10, 2023 at 19:30
  • Before using getAttribute or Trim, save the results of Doc.querySelector into a variable so you can check to make sure it returned something first. You can't get attributes from something it cannot find. Commented Oct 10, 2023 at 19:38
  • please provide this piece of code to save the result of Doc.querySelector in a variable. I'm trying to define variables in the same way as the others, but I'm getting errors. I'm a beginner in VBA, so here's my request Commented Oct 11, 2023 at 4:16

0

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.