[Back]
Calling the Traits webservice from Microsoft Excel 95/97/2000
This tutorial assumes you are using any Microsoft Windows Operating System.
Step 1: Install Microsoft SOAP Toolkit
Download Microsoft's SOAP Toolkit 3.0 or here
Step 2: Create a Visual Basic module using the Visual basic Editor
Launch Excel and open the Visual Basic Editor by going to the Tools menu.
![Menu](https://www.marinespecies.org/aphia/images/webservice_menu.gif)
To make sure the VB Editor knows that you have the SOAP Toolkit installed, select Tools->References. Scroll down the list of libraries and pick "Microsoft Soap Type Library v3.0".
![References](https://www.marinespecies.org/aphia/images/webservice_ref.gif)
Add this piece of code by choosing Insert->Module. Copy this code into your Excel VBA module
Option Explicit
'Excel VBA Function to call the AphiaNameService
Public Function getAphiaID(taxon As String) As Single
Dim objSClient As MSSOAPLib30.SoapClient30
Dim fResult As Single
Set objSClient = New SoapClient30
Call objSClient.mssoapinit(par_WSDLFile:="https://marinespecies.org/traits./aphia.php?p=soap&wsdl=1")
fResult = objSClient.getAphiaID(taxon, True) 'Optional parameters need to be there in VBA
Set objSClient = Nothing
getAphiaID = fResult
End Function
Your screen should look something like this:
![Module](https://www.marinespecies.org/aphia/images/webservice_module.gif)
Close the VB Editor.
Step 3: Using the function in Excel
You can now use the function getAphiaID as you would any built-in Excel function.
Select the cell you want the value displayed in, then go to the Insert menu and choose Function.
In the Paste Function dialog box, scroll down to User Defined functions and you should see getAphiaID listed:
![Function](https://www.marinespecies.org/aphia/images/webservice_function.gif)
The result should be something like this:
![Module](https://www.marinespecies.org/aphia/images/webservice_result.gif)
Credits for this tutorial go to Rod Page.
Download elaborate example for getAphiaRecordById.
Download elaborate example for getAphiaClassificationByID.
|