Excel ActiveSheet.QueryTables.Add和非ASCII字符

时间:2018-10-26 20:53:51

标签: excel vba excel-vba non-ascii-characters

我使用以下代码从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

1 个答案:

答案 0 :(得分:0)

我最终使用了完全不同的方法。我没有创建链接,而是打开页面并将页面复制并粘贴到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