首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Excel vba转换IE.Document为空

Excel vba转换IE.Document为空
EN

Stack Overflow用户
提问于 2019-02-13 17:58:28
回答 1查看 303关注 0票数 1

这是我用来翻译excell表格中的字段的VBA脚本。问题是这个脚本在2个3个月前对我有效,但现在翻译后IE.Document是空的。页面提供了正确的翻译,但我无法在excel工作表中获得结果

代码语言:javascript
复制
inputstring = "en"
outputstring = "da"
text_to_convert = str

'open website

IE.Visible = True
IE.navigate "https://translate.google.com/#" & inputstring & "/" & outputstring & "/" & text_to_convert

Do Until IE.ReadyState = 4
    DoEvents
Loop

Application.Wait (Now + TimeValue("0:00:4"))

Do Until IE.ReadyState = 4
    DoEvents
Loop
test = IE.Document.getElementById("result_box")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-13 19:06:20

使用适当的页面等待。我还使用了不同的元素选择器。

代码语言:javascript
复制
Option Explicit
Public Sub GetTranslation()
    Dim ie As New InternetExplorer, ws As Worksheet
    Dim inputString As String, outputString As String, text_to_convert As String, translation As String
    inputString = "en"
    outputString = "da"
    text_to_convert = "Banana"
    Set ws = ThisWorkbook.Worksheets("Sheet1")

    With ie
        .Visible = True
        .Navigate2 "https://translate.google.com/#" & inputString & "/" & outputString & "/" & text_to_convert
        While .Busy Or .readyState < 4: DoEvents: Wend
        translation = ie.document.querySelector(".translation").innerText
        ws.Cells(1, 1) = translation
        .Quit
    End With
End Sub
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54667280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档