Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub TraduciFrancese()
Dim Rng As Range, cella As Range, objIE As Object
Dim sURL As String, oDocu As Object, oItem As Variant
Dim sTesto As String, sTrad As String, i As Long
On Error GoTo exitSub_
LR = Cells(Rows.Count, "A").End(xlUp).Row
Set Rng = Range("A2:A" & LR)
Set objIE = CreateObject("InternetExplorer.Application")
Application.ScreenUpdating = False
For Each cella In Rng.Cells
sTesto = cella.Value
If sTesto <> "" Then
sTrad = ""
sURL = "h t t p s://translate.google.it/?hl=it&tab=wT#it/fr/" & sTesto ' togli spazi
objIE.navigate sURL
i = 0
Do While (objIE.Busy Or objIE.readyState <> 4) And i < 5000
i = i + 1
DoEvents
Loop
Sleep 500
sTrad = objIE.document.getElementById("result_box").innertext
Application.StatusBar = sTesto & " -> " & sTrad
' Debug.Print sTesto & " -> " & sTrad
cella.Offset(0, 1).Value = sTrad
End If
Next cella
Debug.Print "terminato"
exitSub_:
If TypeName(objIE) = "IWebBrowser2" Then
objIE.Quit
End If
Application.ScreenUpdating = True
Application.StatusBar = False
If Err.Number <> 0 Then
MsgBox "si è verificato un errore! " & i, vbCritical, "ERRORE"
Else
MsgBox "Terminato!"
End If
Set objIE = Nothing
Set oDocu = Nothing
Set oItem = Nothing
End Sub
|