Click here to Skip to main content
15,883,623 members
Articles / Desktop Programming / MFC
Article

Consuming Web Services from MS Excel

Rate me:
Please Sign up or sign in to vote.
2.86/5 (17 votes)
31 Aug 20032 min read 146.1K   1.3K   44   15
How to access a web service from Microsoft Excel

Introduction

Web Services are reusable applications that expose an interface that can be accessed over the internet. Web services use XML to provide a platform and language independent implementation of distributed application services and information.

Web services allow us to utilize the services provided by the other organizations. We can consume the web services not only from applications developed using various programming languages but also from Microsoft office tools like Access, Excel, and Word etc. In this article we will explore how we can access a web service from Microsoft Excel using Microsoft Office XP Web Services Toolkit 2.0, which simplifies the process of accessing and utilizing an XML webservice.

Details

 Sample screenshot

The example includes a webservice, which returns 5 countries and their capitals. Capitals.xls has 2 buttons. When a user clicks on the display button, Capitals.xls sheet accesses the web service and displays the data provided by the webservice. Clicking on the clear button clears the data from the XL sheet.

Sample screenshot

Now lets see how we can develop this application. Lets start by creating an excel sheet. Drag and drop a button from the visual basic toolbox. (You can get the VB toolbox from the View menu). Now to add a reference to the web service . For this we will use the VB editor (Alt-F11). From the tools menu bar add the reference of Microsoft Soap tool kit. Now lets add the web service reference. For this click on the web reference in the tools menu of the VB editor. You can either search for a web service or if you know the URL of a web service u can directly add it. Now you are ready to access the web service. We can do this by creating an object of the web service class and displaying the result in the excel sheet.

VB.NET
Dim module As clsws_Service1
Dim value As String
Dim data() As String
Dim range1 As Range
Dim range2 As Range
Dim j As Integer
Set module = New clsws_Service1
value = module.wsm_getCapitals()
data = Split(value)
j = 0
Application.ActiveSheet.Range("A4").Activate
Set range1 = Range(Range("A4"), Range("A22"))
For Each range2 In range1
    If j < 9 Then
     range2.Offset(0, 3).value = data(j)
     range2.Offset(0, 4).value = data(j + 1)
     j = j + 2
   End If
Next range2

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
India India
Working on .NET for last 6 years. Currently working for TCS.

Comments and Discussions

 
QuestionLicense Pin
marco.gatto1-Nov-12 22:23
marco.gatto1-Nov-12 22:23 
GeneralMy vote of 1 Pin
elomer28-Jul-10 5:00
elomer28-Jul-10 5:00 
GeneralRe: My vote of 1 Pin
Kodanda Pani29-Dec-10 22:57
Kodanda Pani29-Dec-10 22:57 
GeneralWeb Service Toolkit Error Pin
smud13-Nov-06 14:05
smud13-Nov-06 14:05 
GeneralWeb services in Excel w/out programming Pin
dipskinny25-Sep-06 18:39
dipskinny25-Sep-06 18:39 
GeneralSetting up the Webservices Pin
gjenkin4-May-05 2:53
gjenkin4-May-05 2:53 
GeneralRe: Setting up the Webservices Pin
Kodanda Pani4-May-05 18:36
Kodanda Pani4-May-05 18:36 
GeneralRe: Setting up the Webservices Pin
gjenkin10-May-05 2:53
gjenkin10-May-05 2:53 
GeneralRe: Setting up the Webservices.(Help Needed Immediately....) Pin
user3527-Sep-05 3:44
sussuser3527-Sep-05 3:44 
GeneralRe: Setting up the Webservices.(Help Needed Immediately....) Pin
takaka5-Nov-06 17:28
takaka5-Nov-06 17:28 
QuestionSOAP Tool Kit? Pin
rball31-Mar-05 7:30
rball31-Mar-05 7:30 
AnswerRe: SOAP Tool Kit? Pin
Kodanda Pani3-Apr-05 19:17
Kodanda Pani3-Apr-05 19:17 
AnswerRe: SOAP Tool Kit? Pin
gjenkin4-May-05 2:50
gjenkin4-May-05 2:50 
GeneralRe: SOAP Tool Kit? Pin
chethana rao7-Apr-06 20:00
chethana rao7-Apr-06 20:00 
GeneralRe: SOAP Tool Kit? Pin
ChiefOdie24-Oct-06 11:46
ChiefOdie24-Oct-06 11:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.