VBA: WinHttpRequest with Login and Password – Misc Bloglines

February 11th, 2005 | Categories: VBA | Tags:
-->

I learned from the Amazon Web Services workbook that it’s extremely easy to access a REST Web Service using VBA and import the data to an XML list.

One missing piece after viewing the Amazon workbook was how to also send a login and password with a request if needed. Turns out to be very Simple. To send a login and password just add one additional command WinHttpRequest.SetCredentials (Example code below)

I’ve been trying to improve my XML knowledge lately(or lack thereof) by working on a learning project using the Bloglines Web Services, which allows HTTP requests, and returns XML (OPML, Unread Items, etc).

The learning curve I encountered was instead of simply pushing the XML through a map into cells, I wanted to use MSXML2 (Excel’s XML parser) to gain total control of the data to populate Treeviews, Listboxes, and other UserForm stuff.

The project goal is to to read my bloglines subscriptions in Excel(I’m 60% done), sorta like a Bloglines version of Colo’s EZRSS, then possibly port the effort to OutLook when I’m finished(another learning curve).

Here is example code to pull your Bloglines subscriptions into Excel, it sends your Username and Password for authentication:

'HttpRequest SetCredentials flags.
Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0

Private Sub ListSubs()
Dim MyRequest As New WinHttpRequest

    MyRequest.Open "GET", _
    "http://rpc.bloglines.com/listsubs"

    'Set credentials
    MyRequest.SetCredentials "USERNAME", "PASSWORD", _
    HTTPREQUEST_SETCREDENTIALS_FOR_SERVER

    ' Send Request.
    MyRequest.Send

    'And we get this response
    MsgBox MyRequest.ResponseText

End Sub

Notes:
Set a reference to Microsoft WinHTTP Services

Replace USERNAME and PASSWORD with your Bloglines info

This returns the XML to a msgbox for demonstration, you can import it a map or load it to a MSXML2.DOMDocument(I’ve got working code, I’m still experimenting, I’ll follow up). Here is a snippet of the msgbox:

bloglinessnippet

Can't get the tutorial to work for you? Need help with your code?
Get answers right away at our AE Excel Support Forums!
  1. August 24th, 2005 at 06:36
    Reply | Quote | #1

    Thanks for this, it’ll help get me started however, the place I’d really like to use this (at the office) requires connecting through a proxy server. Can you direct me to something on using WinHttpRequest with a proxy? I’ll of course do my own research too, but if you know of anything useful, do tell!

    Thanks for this great resource!

    MLG4035

  2. Mark
    August 24th, 2005 at 16:58
    Reply | Quote | #2

    Good question. I have access to some confusers behind some serious lockdown currently so maybe I’ll do some experimenting myself.

    If you do find a way to tunnel out using excel drop a note or email a post about it and I’ll publish it.

    Mark

  3. August 25th, 2005 at 20:40
    Reply | Quote | #3

    Mark,

    I found what I was looking for: you can use the Windows ‘Proxy Configuration tool’ (C:windowssystem32proxycfg.exe) to set the proxy information for WinHttpRequest (I found a posting on a talkaboutsoftware.com forum)!

    Using the command “proxycfg.exe -u” will set the current user’s Internet Explorer proxy settings for use by any application that uses WinHttpRequest! Woo hoo!

    I tried this already and it works like a charm with Excel 2000 on Windows XP!

    Anyway, thanks again for this great website!
    MLG4035

  4. August 26th, 2005 at 12:55
    Reply | Quote | #4

    Good stuff paul, I’ll post it for others. I also found it may work using HTTPREQUEST_SETCREDENTIALS_FOR_PROXY

    Link: MSDN Set Credentials