I’m trying to do a simple macro with a site that beautify code,
1- paste a text in input box to the left
2- Click “Beautify” button
3- Copy the result of output box to the right
This is my current code but I’m getting run time error 91 Object variable or With block variable not set
for line inputBox.innerText = ...
Sub Test()
Dim url As String
Dim oHttp As New MSXML2.XMLHTTP60
Dim inputBox As Object, outputBox As Object
Dim myBtn As Object
url = "https://www.tutorialspoint.com/online_ruby_formatter.htm"
oHttp.Open "GET", url, False
oHttp.send
Dim html As New HTMLDocument
html.body.innerHTML = oHttp.responseText
'Inserting code to beautify
Set inputBox = html.getElementsByClassName("ace_content")(1)
inputBox.innerText = "if" & vbCr & "sometext" & vbCr & "elsif" & vbCr & "other text" & vbCr & "else" & vbCr & "last text" & vbCr & "end" & vbCr
'Click button to beautify
Set myBtn = html.getElementsByClassName("l-btn-text")(7)
myBtn.Click
'Get text of beautified code
Set outputBox = html.getElementsByClassName("ace_content")(0)
Debug.Print outputBox.innerText
End Sub