IE.Document.getElementsByName("name").Value = "Value" not working - excel

When I try and do this, it throws a number of errors at me depending on other bits of my code, such as the method is not associated with that object or an unspecified error.
I am trying to go down a list of Excel cells with strings and use a web form to search for those strings.
My code currently looks like this:
Sub YSF_automation()
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "URL"
While IE.Busy
DoEvents
Wend
IE.Document.getElementsByName("ElementName")(0).Value = "test"
End Sub

Try the below
Option Explicit
Dim IE as Object
Sub YSF_automation()
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "URL"
While IE.Busy
DoEvents
Wend
set document = IE.document
with document
.getElementsByName("ElementName")(0).value="test"
end with
End Sub

Related

How can I loop the script 1000 times to get the data in different cells and get URL value from different cells?

How can I loop the script 1000 times to get the data in different cells and get URL value from different cells?
Private Sub CommandButton1_Click()
Dim ie As InternetExplorer
Dim ht As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate Workbooks("FINAL-1").Worksheets("sheet1").Range("A2").Value
Do While ie.readyState <> READYSTATE_COMPLETE
Loop
Set ht = ie.document
Workbooks("FINAL-1").Worksheets("sheet1").Range("C").Value = ht.getElementById("addr1").Value
'Workbooks("FINAL-1").Worksheets("sheet1").Range("C2").Value = ht.getElementById("fullName").Value
'Workbooks("FINAL-1").Worksheets("sheet1").Range("d2").Value = ht.getElementById("addr1").Value
Workbooks("FINAL-1").Worksheets("sheet1").Range("D").Value = ht.getElementById("dob").Value
Workbooks("FINAL-1").Worksheets("sheet1").Range("E").Value = ht.getElementById("applyDte").Value
Workbooks("FINAL-1").Worksheets("sheet1").Range("B").Value = ht.getElementById("idNo").Value
'Workbooks("FINAL-1").Worksheets("sheet1").Range("G2").Value = ht.getElementById("genderMtdtId").Value
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate Workbooks("FINAL-1").Worksheets("sheet1").Range("A2").Value
Do While ie.readyState <> READYSTATE_COMPLETE
Loop

Retrieve the URL from the Internet Explorer

i am struggling on the following: I try to open an URL(Link), become redirected to a new URL and retrieve this new URL into a Cell in my excel worksheet.
I have written the following code but it is not retrieving the new URL and is not quitting the Internet Explorer at the end:
Sub Get_URL()
Dim ISIN As String
Dim Link As String
Dim IE As Object
ISIN = Range("A1").Value
Link = "https://www.finanzen.net/suchergebnis.asp?_search=" & ISIN
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.Navigate Link
End With
Range("A2") = IE.LocationURL
Set IE = Nothing
IE.Quit
End Sub
The ISIN in A1 is KYG875721634.
I would be very glad if some of you guys could find the problem. Thank you very much!
Greetings, Robin
This works. Read the comments please:
Sub Get_URL()
Dim ISIN As String
Dim Link As String
Dim IE As Object
'ISIN = Range("A1").Value
ISIN = "KYG875721634"
Link = "https://www.finanzen.net/suchergebnis.asp?_search=" & ISIN
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.Navigate Link
End With
'You must wait to load the page
Do While IE.readystate <> 4: DoEvents: Loop
'Range("A2") = IE.LocationURL
MsgBox IE.LocationURL
'First quit the IE
'because this step needs the reference ;-)
IE.Quit
Set IE = Nothing
End Sub
There're two issues in your code:
You need to add a wait to load page.
Do Until IE.readyState = 4
DoEvents
Loop
First quit IE. If you first set IE to Nothing then there will be no reference to IE when quit.
IE.Quit
Set IE = Nothing
The final code is like this which can work well:
Sub Get_URL()
Dim ISIN As String
Dim Link As String
Dim IE As Object
ISIN = Range("A1").Value
Link = "https://www.finanzen.net/suchergebnis.asp?_search=" & ISIN
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate Link
Do Until IE.readyState = 4
DoEvents
Loop
Range("A2") = IE.LocationURL
IE.Quit
Set IE = Nothing
End Sub
Result:

Website to excel data fetching

Can anyone please help in fetching data from website to excel using VBA, i need property address in excel cell:
Option Explicit
Sub test()
Dim ie As New InternetExplorer
ie.navigate "xyz.org"
ie.Visible = True
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Dim doc As HTMLDocument
Set doc = ie.document
ie.document.all("input-search-field").Value = Range("b1").Value
Dim obj As Object
For Each obj In ie.document.getElementsByTagName("BUTTON")
If obj.className = "btn btn-default search-button" Then
obj.Click
Exit For
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Dim isPropertyAddr As Boolean
isPropertyAddr = ie.document.getElementById("LoanObject").ie.document.getelementbytagname("SPAN")
isPropertyAddr = True
Debug.Print ie.document.getattributes("classname"), ie.document.getattributes("tagname")
MsgBox obj.innerText
dom code
Try something like this
IsAddressFound = False
For Each obj In ie.document.getElementById("LoanObject").getElementsByTagname("SPAN")
If InStr(obj.Innertext, "Property Address") > 0 Then
IsAddressFound = True
End If
If IsAddressFound Then
Debug.Print obj.Innertext 'Your address populates here
IsAddressFound = False
End If
Next
Thanks

VBA to select list in IE

I've been trying to use VBA to open an IE window and select from one of the dropdown list showing bwin but failed. Any advice?
Private Sub OKButton_Click()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Silent = True
.Visible = True
.Navigate "http://www.yahoo.com/"
End With
While ie.ReadyState <> 4 Or ie.Busy: DoEvents: Wend
Set AvailableLinks = oIE.document.getelementbyid("list-listing").getelementsbytagname("a")
For Each cLink In AvailableLinks
If cLink.innerhtml = "????" Then
cLink.Click
End If
Next cLink
End Sub

Error 424 In VB

I am trying to create the Automation using VB to log in to website by using the User ID & Password, but its giving me error 424 Object required as shown below the VB Code
Sub Test()
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
IE.Navigate ("https://appsglobal.nike.com/Citrix/AppsGlobal/auth/login.aspx" & ActiveCell)
Do
If IE.ReadyState = 4 Then
IE.Visible = False
Exit Do
Else
DoEvents
End If
Loop
IE.Document.Forms(0).all("User Name").Value = "UserID"
IE.Document.Forms(0).all("Password").Value = "Password"
IE.Document.Forms(0).submit
End Sub

Resources