Forum Discussion
my vba codes are in french, how can i quickly convert them to english
I am trying to convert my vba codes from french to english; there are 11 sheets and each has at least one code. I've just been slowly translating the codes with ChatGPT and Google Translate, but both of those have a limit to how much they can translate at a time.
Is there a quicker way for me to translate the codes?
4 Replies
- NikolinoDEGold Contributor
Attached is a link and VBA Code with a solution approach
With Google translator service.
The idea of using this automatically with VB/VBA.
Requirements are: Connection to the web and Internet Explorer/Edge.
Here is the procedure:
Code:
Public Function TranslateByGoogle(OrigineText As String, _ LangCodeFrom As String, _ LangCodeTo As String, _ TranslateText As String, _ Optional UniCodeID As Long, _ Optional TimeOutSeconds As Integer = 3, _ Optional ErrSilent As Boolean = False) As Boolean 'Copyright by Jean Pierre Allain Dim ieOBJ As Object, WaitTime As Date ' Google website Const WebSite As String = "http://translate.google.com" ' error handling OnError GoTo ErrHandler If Len(OrigineText) > 0 And Not LangCodeFrom = LangCodeTo Then ' Create IE object (instance). Set ieOBJ = CreateObject("InternetExplorer.Application") 'Call up website with parameters ieOBJ.Navigate WebSite & "/?sl=" & LangCodeFrom & _ "&tl=" & LangCodeTo & "#" & LangCodeTo & "|" & _ LangCodeFrom & "|" & OrigineText ' Set TimeOut WaitTime = Now + TimeValue("00:00:" & TimeOutSeconds) On Error Resume Next do ' Read Google result TranslateText = ieOBJ.Document.getElementById("result_box").innerText If Now() >= WaitTime Then Exit Do Loop While TranslateText = "" OnError GoTo ErrHandler ' Read result (translation) If Len(TranslateText) > 0 And Not TranslateText = OrigineText Then ' If necessary, convert the translation into the specified national language If UniCodeID <> 0 Then TranslateText = StrConv(TranslateText, vbUnicode, UniCodeID) End If TranslateByGoogle = True End If End If ExitProc: On Error Resume Next ' Destroy objects ieOBJ.Quit Set ieOBJ = Nothing Exit function ErrHandler: If Not ErrSilent Then MsgBox Err.Description, vbCritical, Err.Number End If Resume ExitProc End function
Code
Dim Result As String ' Language codes must be passed as ISO country codes ' Example: German = DE ' English = EN ' French = FR ' Polish = PL ' etc. If TranslateByGoogle("That was easy!", "DE", "EN", Result) Then MsgBoxResult End If
Maybe it will help you 🙂
- LilYawneyBrass ContributorI'm having trouble figuring out how to run this code; how do I use it?
- NikolinoDEGold Contributor
The Translate feature is currently available for Word, Excel, OneNote, Outlook, and PowerPoint.
Translate text into a different language
In addition, a file for your own translator to install yourself, I have it from the Internet.
Find creator and page in the file. Maybe it will help you.
At the same time I found the site of the creator of the first code.
Here the link: Use Google Translate with VB and Internet Explorer
Hope it helps!