去年,我通过谷歌翻译的这段代码没有问题。但是现在它给了我一个424
错误。
需要对象。
我张贴了我的整个代码。但是失败的字符串是:
arr_Response = Split(.Document.getElementById("result_box").innerHTML,
"<span class")
VBA:
Public Sub TranslateDescribtion()
With Ark3.Range("B2", "B105")
' Find translation language
Worksheets("TranslationLanguageLookUp").Activate
TranslateLanguageAdress = .Find(What:=TranslateLanguagesVariable, LookAt:=xlWhole).Address
TranslateLanguageSyntax = Range(TranslateLanguageAdress).Offset(0, 1).Text
Worksheets("Equipments").Activate
End With
'Original Language to translate from
Const INPUT_LANG As String = "en"
'Progress text shown i processbar
Dim ws_ActiveWS As Worksheet
Dim r_ActiveCell As Range, r_InputRange As Range
Dim s_InputStr As String, s_InputLang As String, s_OutputLang As String, arr_Response() As String, s_Translation As String
Dim o_IE As Object
Dim i As Long
Dim v As Variant
Set o_IE = CreateObject("InternetExplorer.Application")
'Declare the inputstring with text to be translated
s_InputStr = DescribtionTVariable
'Output-language
s_OutputLang = TranslateLanguageSyntax
'Navigate to translate.google.com
With o_IE
.Visible = False 'Run IE in background
.Navigate "http://translate.google.com/#" & INPUT_LANG & "/" _
& s_OutputLang & "/" & s_InputStr
'Split the responseText from Google
arr_Response = Split(.Document.getElementById("result_box").innerHTML, "<span class")
'Remove html from response, and construct full-translation-string
For Each v In arr_Response
s_Translation = s_Translation & Replace(v, "<span>", "")
s_Translation = Replace(s_Translation, "</span>", "")
s_Translation = Replace(s_Translation, """", "")
s_Translation = Replace(s_Translation, "=hps>", "")
s_Translation = Replace(s_Translation, "=atn>", "")
s_Translation = Replace(s_Translation, "=hps atn>", "")
Next v
If (s_Translation <> vbNullString) Then
DescribtionsTranslatedValue = s_Translation
'Cleanup
o_IE.Quit
'Set o_MSForms_DataObject = Nothing
Set ws_ActiveWS = Nothing
Set r_ActiveCell = Nothing
Set o_IE = Nothing
End With
End Sub
答案 0 :(得分:1)
我不认为自己拥有相同的网址,因此提供完整的网址会有所帮助。关于您提到的课程,您可以使用
Debug.Print ie.document.querySelector(".tlid-translation.translation").innerText