2

I want simple and easy integration of python and vba.

People, reading this may kill me if they meet me in person after reading this but I am using django development server for this purpose.

Is there any simple and better way.

Just for example:

I want to export comma separated string as excel file using python moduel openpyxl.

This is django app url.py

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'identifier(.*)$', views.demo, name='index')
]

This is django app views.py

from django.http import HttpResponse
from openpyxl import Workbook

def demo(request, data):
    (identifier, numbers, filepath) = data.split(';;;')
    wb = Workbook()
    ws_sent = wb.active
    for number in numbers.split(','):
        ws_sent.append((number.strip(),))
    wb.save(filepath + identifier + '.xlsx')
    return HttpResponse(identifier + " : Completed")

vba:

Sub demohttp()
    Set httpobject = CreateObject("MSXML2.XMLHTTP")
    url = "http://localhost:8000/appname/identifier;;;1,2,3,4,5,6,7,8,9;;;C:/ActiveDocument.Path"
    httpobject.Open "GET", url, False
    httpobject.send
    msgbox httpobject.responseText
End Sub

This is blazing fast compared to: calling python from vba shell functions

This is amazingly simple compared to: automating excel from word vba. Excel is just an example. I have so many python scripts I wanted to convert to django apps.

Questions 1) is there any downfall? I have checked it for my maximum number count up to 1200 unique numbers.

2) is there any better way? I tried to learn server side com but looks like mess.

Rahul
  • 10,830
  • 4
  • 53
  • 88
  • The Django development server is perfectly fine to use for development, after all, that's what it's for. However, if you use it in a production environment that's exposed to the real Internet then you deserve all the problems that you _will_ get. – PM 2Ring Jan 30 '17 at 12:16
  • Am I understanding this correctly? 1. Want to reuse Python scripts without porting them to VBA 2. Calling them from VBA through the command-line is slow 3. Exposing these scripts through Django with URL parameters is actually faster and simpler. 4. And the question is, "is there any better way? I tried to learn server side com but looks like mess." – Blackhawk Jan 30 '17 at 16:54
  • If my assumptions are correct, I suggest you maybe take a look [here](http://stackoverflow.com/questions/3567365/calling-python-script-from-excel-vba) for other ways of calling your Python scripts from VBA. – Blackhawk Jan 30 '17 at 16:58

0 Answers0