Calling web service using VBA code in Excel 2010
Asked Answered
C

4

19

I am trying to write some VBA code in Excel 2010 that would consume a web service. I am unable to find any related resources on the internet. Can someone please tell me how to do this.

Chole answered 19/8, 2010 at 12:45 Comment(7)
Jimmy Peña's blog has an excellent series of articles on doing just that. codeforexcelandoutlook.com/blog/category/internet-explorerVelarize
unfortunately there was nothing related to this particular problem in this siteChole
Search for web services on his blog, you should find something. codeforexcelandoutlook.com/blog/2010/06/…Stately
You might find this useful. It should apply equally well to Excel 2010. Found this too.Proclaim
This is an old question but... I've just discovered the '=WEBSERVICE' function in Excel 2013. Simple as can be... see blogs.office.com/2013/03/21/…Roping
You may be interested in PowerQuery too: blog.crossjoin.co.uk/2014/03/26/…Hinson
link: codingislove.com/http-requests-excel-vba using the MSXML2.XMLHTTP60 object seems to help in my case, please refer to the linkQuartersaw
H
7

I don't think the post marked as the answer is right - it links to the Excel 2003 solution, which was based on the MS Office Web Services Toolkit. That solution is no longer valid as the Toolkit is not supported any more. See: MSDN - Consuming Web Services in Excel 2007. The link provides a solution for Excel 2007 which can be transposed to Excel 2010. You will need Visual Studio 2010 with Microsoft Office Developers Tools though. It also means utilising .Net Framework and coding in C# or VB.NET.

Honorarium answered 12/4, 2011 at 10:36 Comment(7)
-1, the question asked for VBA. This reply requires Visual Studio.Quickstep
Fair enough. In my opinion MS would like to have VBA dead and it is pushing .net solutions for Office. On the seperate note, you don't have to use Visual Studio. You can use NotePad and command line compiler.Honorarium
One would be surprised about the number of banks (even very large) that would nearly stop working if VBA disappeared tomorrow !!!Quickstep
Funny, I am working for one of those and they would be very happy with removing any code from an Excel binary file. Some of them have even done that; they have VBA modules stored in a code repository and a workbook is rebuilt from those for each release.Honorarium
My point is that MS actively discourage VBA coding and try to shift development to .net and Visual Studio. The removal of MS Office Web Services Toolkit is an example. So VBA will not disappear tomorrow, but its days are numbered. Like it or not.Honorarium
@Honorarium 2020 now and still going. How many days left? :)Hemiterpene
@byte me - I don't know. We stopped any VBA dev - replaced by Excel-DNA, Pandas and microservices. Users are allowed to do prototyping in VBA, but it does not go to PROD. Does it answer your question?Honorarium
G
38

I struggled with the same question on a recent project of mine where I wanted to talk to Trello and Salesforce in pure VBA without installing any plugins, opening up Visual Studio, or other hacks. Ended up writing my own library (based heavily on one of my favorites, RestSharp).

Warning, shameless plug: https://github.com/VBA-tools/VBA-Web

Some fun features include Mac support(!), authentication (Http Basic, OAuth1, OAuth2, and others), Async support, and JSON parsing (thanks to VBA-JSON)

It's working awesomely in Excel 2010 and 2013 (and most likely 2007) and I've got it working with Salesforce, Trello, Basecamp, Google Maps, and it should work with pretty much any webservice.

Gory answered 4/4, 2013 at 2:57 Comment(1)
Wow. Great piece of work, have not tested it yet, but looks awesome. Thanks a lot!Honorarium
H
7

I don't think the post marked as the answer is right - it links to the Excel 2003 solution, which was based on the MS Office Web Services Toolkit. That solution is no longer valid as the Toolkit is not supported any more. See: MSDN - Consuming Web Services in Excel 2007. The link provides a solution for Excel 2007 which can be transposed to Excel 2010. You will need Visual Studio 2010 with Microsoft Office Developers Tools though. It also means utilising .Net Framework and coding in C# or VB.NET.

Honorarium answered 12/4, 2011 at 10:36 Comment(7)
-1, the question asked for VBA. This reply requires Visual Studio.Quickstep
Fair enough. In my opinion MS would like to have VBA dead and it is pushing .net solutions for Office. On the seperate note, you don't have to use Visual Studio. You can use NotePad and command line compiler.Honorarium
One would be surprised about the number of banks (even very large) that would nearly stop working if VBA disappeared tomorrow !!!Quickstep
Funny, I am working for one of those and they would be very happy with removing any code from an Excel binary file. Some of them have even done that; they have VBA modules stored in a code repository and a workbook is rebuilt from those for each release.Honorarium
My point is that MS actively discourage VBA coding and try to shift development to .net and Visual Studio. The removal of MS Office Web Services Toolkit is an example. So VBA will not disappear tomorrow, but its days are numbered. Like it or not.Honorarium
@Honorarium 2020 now and still going. How many days left? :)Hemiterpene
@byte me - I don't know. We stopped any VBA dev - replaced by Excel-DNA, Pandas and microservices. Users are allowed to do prototyping in VBA, but it does not go to PROD. Does it answer your question?Honorarium
R
3

FWIW as of the time of posting I've found that the old Web References Toolkit of Excel 2003 still produces working VBA code in Excel 2007/10 (note that there have been some shaky moments with various Windows updates over the last 18 months that has stopped this code working so I wouldn't consider my solution 'reliable').

My horrible hack involves installing Excel 2003, then the Web References Toolkit, then installing Excel 2007 or Excel 2010. I've set up 3 PCs using this hack and all are producing working VBA code to consume asmx web services (I haven't tried connecting with other types of web service but I don't see why they wouldn't work).

The official MS method, using VSTO, is a step too far for some of our clients and this VBA hack has kept them happy.

Roping answered 22/7, 2012 at 19:53 Comment(0)
F
0

Windows Communication Foundation (WCF) service moniker to integrate Web services into COM-based development environments, such as Microsoft Office Visual Basic for Applications (Office VBA) or Visual Basic 6.0. For detail see link https://learn.microsoft.com/en-us/dotnet/framework/wcf/samples/using-the-wcf-moniker-with-com-clients

Fultz answered 14/9, 2017 at 10:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.