Ok, so I'm working on a macro to automate data entry into a website. I've gotten stuck at the point of trying to click on a new link within and iframe. After a lot of googling I found that there is a handling issue with IE and tried to employee a work around someone suggested. The problem is I get stuck in a loop with this workaround, when I "fix" (by replaceing = with <>) the work around so it's not stuck I get the automation error I got before.
Below is the code that I'm using and I've attached the HTML;
Sub AUTOFILL()
Dim IE As Object
Dim doc As HTMLDocument
Dim iframe As HTMLIFrame
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "Ally Auto Dealer Services | Financing, Training, Rewards & More | Ally Auto"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
IE.document.getElementById("user").Value = "USERNAME"
IE.document.getElementById("password").Value = "PASSWORD"
IE.document.getElementById("processLogin").Click
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
IE.document.getElementsByTagName ("a")
Dim VPClink As HTMLAnchorElement
Set VPClink = Nothing
Do
Set VPClink = doc.querySelector("[data-track-name='Vehicle Protection Center']")
DoEvents
Loop While VPClink Is Nothing
VPClink.Click
IE.document.querySelector("[data-track-name='Vehicle Protection Center']").Click
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Dim baseURL As String
Dim HTMLdoc As HTMLDocument
Dim workFrame As HTMLIFrame
Dim acctInput As HTMLInputElement
Set IE = New InternetExplorer
With IE
.Visible = True
IE.Navigate "Ally Financial (API securedealerally.) - Sign In"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
'Craziest workaround ever due to bugged IE Eventhandling, like this is gets stuck in the loop
Do While IE.readyState = 4: DoEvents: Loop
Do Until IE.readyState = 4: DoEvents: Loop
'This is the line that gives me an automation error
IE.document.getElementsByTagName("iframe")(0).contentDocument.getElementById("startNewQuote").Item(0).innerHTML.Click
'<a title="Start a New Quote" class="primary-btn floatright nav-link" id="startNewQuote" href="/qps/getCreateQuote"><span class="marginTop10 marginLeft10px">Start a New Quote </span></a>
End With
End Sub
Below is the code that I'm using and I've attached the HTML;
Sub AUTOFILL()
Dim IE As Object
Dim doc As HTMLDocument
Dim iframe As HTMLIFrame
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "Ally Auto Dealer Services | Financing, Training, Rewards & More | Ally Auto"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
IE.document.getElementById("user").Value = "USERNAME"
IE.document.getElementById("password").Value = "PASSWORD"
IE.document.getElementById("processLogin").Click
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
IE.document.getElementsByTagName ("a")
Dim VPClink As HTMLAnchorElement
Set VPClink = Nothing
Do
Set VPClink = doc.querySelector("[data-track-name='Vehicle Protection Center']")
DoEvents
Loop While VPClink Is Nothing
VPClink.Click
IE.document.querySelector("[data-track-name='Vehicle Protection Center']").Click
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Dim baseURL As String
Dim HTMLdoc As HTMLDocument
Dim workFrame As HTMLIFrame
Dim acctInput As HTMLInputElement
Set IE = New InternetExplorer
With IE
.Visible = True
IE.Navigate "Ally Financial (API securedealerally.) - Sign In"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
'Craziest workaround ever due to bugged IE Eventhandling, like this is gets stuck in the loop
Do While IE.readyState = 4: DoEvents: Loop
Do Until IE.readyState = 4: DoEvents: Loop
'This is the line that gives me an automation error
IE.document.getElementsByTagName("iframe")(0).contentDocument.getElementById("startNewQuote").Item(0).innerHTML.Click
'<a title="Start a New Quote" class="primary-btn floatright nav-link" id="startNewQuote" href="/qps/getCreateQuote"><span class="marginTop10 marginLeft10px">Start a New Quote </span></a>
End With
End Sub