'VBA Issue Excel
i am trying to add a translator in Excel, but i can't figure out where the mistake is in my Code: I am trying to add a translator in Excel via VBA. The problem i am having is that i can't identify the error in my code below. I am not that profficient in Vba, and i need some help and guidance on it. The translator was mostly thought by myself, and with a little help from youtoube from a guy.
Option Explicit
Dim Output As String
Sub Google_Translate()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim i, colcnt As Interior
co1cnt = ActiveSheet.UsedRange.Columns.Count
For i = 1 To co1cnt
If Cells(1, i).Value <> "" Then
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.Calculation = x1calculationAutomatic
End Sub
Public Function autotranslate(ByVal Text As String, Optional LanguageFrom As LanguageCode, Optional Languageto As LanguageCode) As String
Dim angfrom As String, langto As String, ie As InternetExplorer, url As String, myarray
If IsMissing(LanguageFrom) Then
LanguageFrom = inputAuto
End If
If IsMissing(Languageto) Then
Languageto = returnEnglish
End If
myarray = Split(langcode, ",")
langfrom = myarray(LanguageFrom)
langto = myarray(Languageto)
url = "Http://translate.google.com/#" & langfrom & "/" & langto & "/" & Text
Set ie = New InternetExplorer
ie.Visible = False
ie.navigate url
Do Until ie.ReadyState = 4
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:5"))
Do Until ie.ReadyState = 4
DoEvents
Loop
Dim doc As HTMLDocument
Set doc = ie.Document
autotranslate = ie.Document.getElementsByClassName("tlid-translation translation")(0).innerText
Output = autotranslate
ie.Quit
Set ie = Nothing
End Function
Solution 1:[1]
There are lots of small errors in your code that are subtle and hard to find if you just copy a chunk of code rather than build it up step by step. Some examples:
Dim i, colcnt As Interior
co1cnt = ...
Interior
is probably meant to be Integer
.
The variable is declared as colcnt
but you wrote co1cnt
(with digit 1 instead of L) on the next row.
The For
statement is missing its Next
. Same goes for If
, missing its End If
.
There is a lot more. Start over and build it up one step at a time.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sam |