我有条形码阅读器和一堆书。对于每本书,我想在Excel电子表格中列出书名和作者。

我的观点是,将某些VBA代码连接到Amazon Web服务会使此过程变得更容易。

我的问题是-以前没有人这样做吗?你能给我指出最好的例子吗?

最佳答案

我认为这是一个简单的谷歌搜索,但结果却比我预期的要困难得多。

实际上,我无法找到基于VBA ISBN的程序来从网络上获取图书数据,因此决定做一个。

这是一个使用xisbn.worldcat.org服务的VBA宏。示例here.。这些服务是免费的,不需要身份验证。

为了能够运行它,您应该在“工具”->“引用”(在VBE窗口中)中检查“Microsoft xml 6.0”库。

该宏从当前单元格中获取ISBN(10位数字),并在下面两列中填写作者和标题。您应该能够轻松遍历整列。

该代码已经过测试(很好),但是其中没有错误检查。

 Sub xmlbook()
 Dim xmlDoc As DOMDocument60
 Dim xWords As IXMLDOMNode
 Dim xType As IXMLDOMNode
 Dim xword As IXMLDOMNodeList
 Dim xWordChild As IXMLDOMNode
 Dim oAttributes As IXMLDOMNamedNodeMap
 Dim oTitle As IXMLDOMNode
 Dim oAuthor As IXMLDOMNode
 Set xmlDoc = New DOMDocument60
 Set xWords = New DOMDocument60
 xmlDoc.async = False
 xmlDoc.validateOnParse = False
 r = CStr(ActiveCell.Value)

 xmlDoc.Load ("http://xisbn.worldcat.org/webservices/xid/isbn/" _
              + r + "?method=getMetadata&format=xml&fl=author,title")

 Set xWords = xmlDoc

     For Each xType In xWords.ChildNodes
         Set xword = xType.ChildNodes
         For Each xWordChild In xword
             Set oAttributes = xWordChild.Attributes
             On Error Resume Next
             Set oTitle = oAttributes.getNamedItem("title")
             Set oAuthor = oAttributes.getNamedItem("author")
             On Error GoTo 0
         Next xWordChild
     Next xType
  ActiveCell.Offset(0, 1).Value = oTitle.Text
  ActiveCell.Offset(0, 2).Value = oAuthor.Text
 End Sub

由于他们采用了新的“简单易懂”的身份验证协议(protocol),所以我没有去过亚马逊...

关于vba - 图书 list -使用Excel VBA条码查询从亚马逊获取图书详细信息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3903731/

10-10 18:53