我在A栏中有一大串单词,我想使用excel来查找google或bing对每个单词的大量定义。Excel在研究中有一个内置的函数,它将显示bing的定义,但是您必须手动完成每个单词的操作。
我尝试了下面链接中列出的方法,但是它是旧的,函数一直返回错误的“公式中使用的值是错误的数据类型”在VBA中查找单词的英文定义
如果有人知道一个程序或网站,将查找谷歌的定义一大串词,这也是有帮助的。
发布于 2015-07-20 23:26:54
应该有比我下面的代码更有效的方法来做到这一点。它利用Dictionary.com提供的服务。
您可以在工作表中使用它作为函数,比如在A1中有“比萨饼”,然后在A2中使用=DictReference(A1)来显示定义。但是,我只对它进行了编码,以返回第一个定义。
Option Explicit
Const URL_SEARCH = "http://dictionary.reference.com/browse/<WORD>?s=t"
Function DictReference(ByVal SearchWord As Variant) As String
On Error Resume Next
Dim sWord As String, sTxt As String
sWord = CStr(SearchWord)
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", Replace(URL_SEARCH, "<WORD>", sWord), False
.Send
If .Status = 200 Then
sTxt = StrConv(.ResponseBody, vbUnicode)
' The definition of the searched word is in div class "def-content"
sTxt = Split(sTxt, "<div class=""def-content"">")(1)
sTxt = Split(sTxt, "</div>")(0)
' Remove all unneccessary whitespaces
sTxt = Replace(sTxt, vbLf, "")
sTxt = Replace(sTxt, vbCr, "")
sTxt = Replace(sTxt, vbCrLf, "")
sTxt = Trim(sTxt)
' Remove any HTML codes within
sTxt = StripHTML(sTxt)
Else
sTxt = "WinHttpRequest Error. Status: " & .Status
End If
End With
If Err.Number <> 0 Then sTxt = "Err " & Err.Number & ":" & Err.Description
DictReference = sTxt
End Function
Private Function StripHTML(ByVal sHTML As String) As String
Dim sTmp As String, a As Long, b As Long
sTmp = sHTML
Do Until InStr(1, sTmp, "<", vbTextCompare) = 0
a = InStr(1, sTmp, "<", vbTextCompare) - 1
b = InStr(a, sTmp, ">", vbTextCompare) + 1
sTmp = Left(sTmp, a) & Mid(sTmp, b)
Loop
StripHTML = sTmp
End Functionhttps://stackoverflow.com/questions/31509327
复制相似问题