0

I am pretty new to VBA and don't have much experience with it. I have a excel sheet with more then 500 commands for which I want to test if the syntax of the command is correct. To do so I thought about using VBA to automate this process.

For the start I went with just one command to see if it could work, but it does not. My code:

Set IE = CreateObject("InternetExplorer.Application")

IE.Visible = True

URL = "https://www.freeformatter.com/java-regex-tester.html"

IE.Navigate URL

While IE.ReadyState <> 4
    DoEvents
Wend

IE.Document.getElementById("regex").Value = "\b(Yes"
IE.Document.getElementById("input").Value = "Yaes"
IE.Document.getElementById("matchesButton").Click

While IE.ReadyState <> 4
    DoEvents
Wend

Set html = IE.Document

If IsNull(html.getElementById("output")) Then
    Worksheets(12).Range("A2").Interior.ColorIndex = 3
End If


Set IE = Nothing

The input "\b(Yes" should be with syntax errors, so there should be this HTML code:

<div id="output" class="form-wrapper" style="margin-top:20px;padding-left:20px;">

But checking this id="ouptut" does not work, with this error there should no <div id="output" be and therefore IsNull(html.getElementById("output")) should return a Null/True and the excel cell should be marked red.

Can anyone please help me out with my logic error in the code? I tried already hours and should be simple, but I was not able to find a solution via google.

1 Answer 1

1

From this post here, you need to check if the object exists rather than if the element is null.

Create the object first

set Element = html.getElementByID("output") 

Then run your check to see if the object exists

if isObject(Element) then

Try that.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I still get the error: run time error '1004' Application defined or object defined error.

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.