【问题标题】:Excel ActiveSheet.QueryTables.Add and non-ASCII charactersExcel ActiveSheet.QueryTables.Add 和非 ASCII 字符
【发布时间】:2018-10-26 20:53:50
【问题描述】:

我使用以下代码从 www.merriam-webstercom 获取“尖顶”页面。它工作正常,只是音标没有正确显示。我得到了这样的东西: \ˈkÉ™-ËŒspÄt, -spÉ™t 。尝试将音标粘贴到此页面时,我得到了完全相同的涂鸦内容。

我搜索了网络,但没有得到任何有用的线索。

有什么想法吗?谢谢。

Sub import_from_web(ByVal lookup_word As String)

With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;https://www.merriam-webster.com/dictionary/" & lookup_word,   Destination:= _
    Range("$A$1"))
    .Name = "d"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .TextFilePlatform = xlMSDOS
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .WebSelectionType = xlEntirePage
    .WebFormatting = xlWebFormattingNone
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
End With
End Sub

【问题讨论】:

  • This 可能有用
  • 谢谢。我实际上尝试过“TEXT”而不是“URL”,但它获取了 HTML 文档(充满了 HTML 标签)。我只想要简单的文本文件。
  • 我在考虑编码问题。如果您尝试将 TextFilePlatform 设置为 65000 或 65001,会发生什么情况?
  • @cybemetic.nomad 感谢您的评论。实际上,该行应该被注释掉,因为我相信它只适用于 TEXT,而不适用于 URL。它一定是早期审判的残余。使用该行,代码无法编译。
  • 65001 实际上保留了音标。无论如何要删除 HTML 标签并只留下简单的文本?这可能是我唯一的选择。

标签: excel vba non-ascii-characters


【解决方案1】:

我最终使用了一种完全不同的方法。我没有创建链接,而是打开页面并将页面复制并粘贴到 Excel。

感谢这个帖子:

Excel2010: PasteSpecial failing when copying from IE

Sub search_paste(ByRef IE As Object, ByVal lookup_word As String)

' this sub can handle non-ASCII characters
' it accepts a word from the calling sub and searches the word at Merian-Webster
' it then copies the web page and pastes to the ActiveSheet for further processing

With IE
    .Visible = True
'        .Navigate 
    .Navigate "https://www.merriam-webster.com/dictionary/" & lookup_word ' open the page containing the search word

    Do Until .ReadyState = 4: DoEvents: Loop
End With
DoEvents
IE.ExecWB 17, 0 '// SelectAll
IE.ExecWB 12, 2 '// Copy selection
ActiveSheet.PasteSpecial link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 2014-06-12
    相关资源
    最近更新 更多