Change content in HTML with javascript

Viewed 48

I am using Excel VBA to change content in HTML, I found the following command and it works fine, but when I try to assign the value of a cell in excel it gives an error, please help.

Driver.ExecuteScript ("document.getElementById('tieudeChart').innerHTML = 'textaaa';")

Error: javascripterror: cell1 is not defined

cell1 = Main_AT.Range("ae5").Value
Driver.ExecuteScript ("document.getElementById('tieudeChart').innerHTML= cell1;")
1 Answers

You want the variable outside of the quotes, and since it's a string, put single quotes around it like this:

Driver.ExecuteScript "document.getElementById('tieudeChart').innerHTML= '" & cell1 & "';"

Note: This assumes cell1 does not have a single quote in it.

This should handle the cell having quotes.

Driver.ExecuteScript "document.getElementById('tieudeChart').innerHTML= '" & Replace(cell1, "'", "''") & "';"
Related