読者です 読者をやめる 読者になる 読者になる

DuKiccoの雑記

My Life Is Myself

エクセル,VBA,xml,Pubmed,API,abstract,Title


PubmedAPIを利用して文献IDからAbstractやTitleを読み込むFunction

Sub Pubmed2()

'Functionの使い方
Dim arr As Variant, PubmedID As Long

'情報を取り出したいPubmedID
PubmedID = 2644239

arr = GetTitle(PubmedID)

MsgBox " Abstract " & arr(1)
MsgBox " Title " & arr(2)
End Sub
Function GetTitle(PMID As Long) As String()
'Microsoft XML. v6.0を参照設定
    On Error GoTo Err
    
    Dim xmlNode(2) As String
    ReDim tempgettitle(2) As String
 
    Dim xdoc As MSXML2.DOMDocument
    Dim httpObj As Object
    
    url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=" & PMID & "&retmode=xml"
    
    xmlNode(1) = "//PubmedArticleSet/PubmedArticle/MedlineCitation/Article/Abstract/AbstractText"
    xmlNode(2) = "//PubmedArticleSet/PubmedArticle/MedlineCitation/Article/ArticleTitle"


    Set httpObj = CreateObject("Microsoft.XMLHTTP")
    httpObj.Open "GET", url, False
    httpObj.send ("")
    
    Set xdoc = httpObj.responseXML

    'MsgBox xdoc.XML
    
    For i = 1 To 2
    
        Set xmltxt = xdoc.SelectSingleNode(xmlNode(i))
        tempgettitle(i) = xmltxt.Text
        
    Next
    
    GetTitle = tempgettitle

    Set httpObj = Nothing
    
    Exit Function

Err:

Debug.Print "Error"
    
End Function