Automate Language Translations Using Excel VBA @Exceltrainingvideos
Automate Language Translations Using Excel VBA  @Exceltrainingvideos
Uploaded November 2019 | Updated September 2026, 1 week ago
How to use Google Translate tool in conjunction with Excel VBA to perform automatic language translations. Here's the complete VBA code:

Option Explicit

Public Sub testTranslate()

Dim ws As Worksheet

Set ws = ThisWorkbook.Worksheets("Sheet1")
ws.Cells.Delete

ws.Range("A1") = ("Input")
ws.Range("B1") = "Output"
ws.Range("A2") = "Welcome! What a lovely morning, isn't it?"

ws.Range("B2") = Translate(Range("A2"), "en", "es")
ws.Range("A2:B2").Columns.AutoFit


End Sub


Public Function Translate(strInput As String, strFromSourceLanguage As String, strToTargetLanguage As String) As String
Dim strURL As String
Dim objHTTP As Object
Dim objHTML As Object
Dim objDivs As Object, objDiv As Object
Dim strTranslated As String

' send query to web page
strURL = "translate.google.com/m?hl=" & strFromSourceLanguage & _
"&sl=" & strFromSourceLanguage & _
"&tl=" & strToTargetLanguage & _
"&ie=UTF-8&prev=_m&q=" & strInput

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP") 'late binding
objHTTP.Open "GET", strURL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send ""

' create an html document
Set objHTML = CreateObject("htmlfile")
With objHTML
.Open
.Write objHTTP.responsetext
.Close
End With

'Range("H1") = objHTTP.responsetext

Set objDivs = objHTML.getElementsByTagName("div")

For Each objDiv In objDivs

If objDiv.className = "t0" Then
strTranslated = objDiv.innerText
Translate = strTranslated
End If

Next objDiv



Set objHTML = Nothing
Set objHTTP = Nothing

End Function
Automate Language Translations Using Excel VBAAutomating Analysis of CSV Files with ADO SQLYouTube Shorts Open Any File Using VBA in ExcelExtract Specific Data from MS Word into Excel with VBATREND Function in ExcelConvert Excel Charts to Images Automatically2021 | Recover Data From Protected Excel File| | Using Google SheetsCreate Data Entry Forms under 10 seconds No VBACopy Paste PDF Data into ExcelCreate Plus Minus SwitchCalculate Change Percentage Automatically as you TypeAutomatically Send Message with Image Via Whatsapp
Dinesh Kumar Takyar |

Automate Language Translations Using Excel VBA

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER