You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
I am trying to generate a report for which the data needs to imported by calling a web service. Is it possible to do that from a VBA? If not what are the alternatives for me to do it?
It is possible to use an IE object in Excel to open the page.
First do the following so the appropriate resource is available:
1) From the VBA window click Tools > References
2) Scroll down and check Microsoft Internet Controls
3) Click OK.
After that try this function to get the body:
---------------------------------------------------
Private Function RetrieveSite(sHTTP As String) As String
'Opens file at sHTTP and returns the text part of the body
Dim ieBrowser As InternetExplorer
Set ieBrowser = CreateObject("InternetExplorer.Application")
ieBrowser.Navigate sHTTP
ieBrowser.Visible = True 'set = False if you'd rather not see it open
Do While ieBrowser.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
RetrieveSite = ieBrowser.Document.Body.innerTEXT
ieBrowser.Quit
End Function
---------------------------------------------------
There is more than this available but this should get you pointed in the right direction.