Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to host a webserver in VBA?

Tags:

vba

winsock

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?

like image 838
David Avatar asked Jun 23 '11 01:06

David


People also ask

Can you make a website with VBA?

we can't use Excel and VBA to develop a website. with the help of VBA you can create programs that can enhance the features and functionality of MS Office Applications and make it user Friendly. but it can't be use as an back end to make a website.


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.

like image 134
michaeln Avatar answered Oct 15 '22 00:10

michaeln


http://www.ostrosoft.com/oswinsck.asp#inst

is a winsock type of library which can be used from VBA. It is possible to do what you are looking to do though is not the most efficient thing to do.

I do applaud your tenacity hope it works out for you.

like image 42
Bueller Avatar answered Oct 15 '22 00:10

Bueller


I'm not sure I fully understand the question. Generally, you don't "host a web server", you host a web site.

But if you can do TCP sockets with VBA, then you can make an incredibly simple web server by following the HTTP standard protocol.

Edit: based on your comment, yes you can make a simple web server as long as you can open up a TCP socket.

like image 30
Daniel A. White Avatar answered Oct 15 '22 01:10

Daniel A. White


Well, at the risk of violating the spirit of the question, you can always use VB's support for library functions and just create a library binding to one of a number of C-language web server options (such as http://www.acme.com/software/micro_httpd/, http://www.gnu.org/software/libmicrohttpd/ or http://code.google.com/p/mongoose/). You'd have to make DLLs out of the selected web server but that is reasonably easily done and this will work just fine in VBA.

like image 26
Femi Avatar answered Oct 15 '22 01:10

Femi