Is it possible to host a webserver in VBA?

Viewed 6902

I want to host a web server and want to use VBA to do it. Is this possible? I'm just doing this to prove someone wrong and really want to make this program.

So is it possible to make a really simple web server (just listens for get requests)? Help would be very much appreciated.

EDIT

I'm trying something like this

Sub startServer()
    Set wunsock = CreateObject("OSWINSCK.Winsock")
    wunsock.LocalPort = 80
    wunsock.Listen
End Sub

Sub wunsock_ConnectionRequest(ByVal requestID As Long)
    If sockMain.State <> sckClosed Then
        sockMain.Close
    End If
    sockMain.Accept requestID
End Sub

Private Sub wunsock_DataArrival(ByVal bytesTotal As Long)
    Dim strData As String
    sockMain.GetData strData, vbString
    txtStatus.Text = txtStatus.Text & _
        strData & vbCrLf
End Sub

However it doesn't work?

4 Answers

Although this is a rather old question, I'd still like to mention that I built an Excel hosted REST webserver using plain VBA macros and some Winsock C calls, as proposed by Daniel A. White.

I added this as an answer instead of a comment, since it's built as a modular library, so you can adjust it to your needs, and others might need exactly this kind of library. It can serve both worksheets, basic files and also create custom hooks using an IWebController to listen on specific routes (which was mentioned by OP in a comment):

http://github.com/michaelneu/webxcel

To use it, you'll have to either import the classes/modules into your workbook, or let the build script create a new one for you. See Main.bas on how to start the server from within VBA.

Related