1

This is a VBA script i am using to translate fields in a excell sheet. The problem is that the script works for me about 2 3 month ago, but now the IE.Document is empty after translating. The page comes up with correct translation but i can't get the result inside my excel sheet

inputstring = "en"
outputstring = "da"
text_to_convert = str

'open website

IE.Visible = True
IE.navigate "https://translate.google.com/#" & inputstring & "/" & outputstring & "/" & text_to_convert

Do Until IE.ReadyState = 4
    DoEvents
Loop

Application.Wait (Now + TimeValue("0:00:4"))

Do Until IE.ReadyState = 4
    DoEvents
Loop
test = IE.Document.getElementById("result_box")
QHarr
  • 83,427
  • 12
  • 54
  • 101

1 Answers1

1

Use a proper page wait. I also use a different element selector

Option Explicit
Public Sub GetTranslation()
    Dim ie As New InternetExplorer, ws As Worksheet
    Dim inputString As String, outputString As String, text_to_convert As String, translation As String
    inputString = "en"
    outputString = "da"
    text_to_convert = "Banana"
    Set ws = ThisWorkbook.Worksheets("Sheet1")

    With ie
        .Visible = True
        .Navigate2 "https://translate.google.com/#" & inputString & "/" & outputString & "/" & text_to_convert
        While .Busy Or .readyState < 4: DoEvents: Wend
        translation = ie.document.querySelector(".translation").innerText
        ws.Cells(1, 1) = translation
        .Quit
    End With
End Sub
QHarr
  • 83,427
  • 12
  • 54
  • 101