Python's xlrd module is handy for reading Excel data into SPSS. This tutorial. The installation process is basically identical to installing xlrd as explained below. At a later step, we'll call Python from the Windows Command Line. Do shell script '/anaconda/bin/python -c ' & quoted form of 'import test_file' How can I call this from Excel VBA on Mac? (By the way on Windows, it works easily with WScript.Shell and pywin32 ).
Try this: RetVal = Shell(' ' & ') Or if the python script is in the same folder as the workbook, then you can try: RetVal = Shell(' ' & 'ActiveWorkBook.Path & ') All details within are to be given. indicates change-able fields I guess this should work. But then again, if you script is going to call other files which are in different folders, it can cause errors unless you script has properly handled it.
Hope it helps.
Has anyone successfully executed a Python script from an Excel macro? I've spent the better part of the evening searching for code that would work but so far have been unsuccessful. Unfortunately, the code(s) appear to run successfully (no errors reported) but when I check the data that should have been exported by the python script, its not there. If I run the python script 'GetScores.py' from a command line prompt it works perfectly, but I can't get it to run from a macro. Some of the code I have tried.
Code: #getscores.py import csv with open('nflscores.csv', 'wb') as csvfile: import nfldb db = nfldb.connect q = nfldb.Query(db) q.game(seasonyear=2015, seasontype='Regular', week=6) for g in q.asgames: tmp = (g) spamwriter = csv.writer(csvfile, dialect='excel', quotechar=' ', quoting=csv.QUOTEMINIMAL) spamwriter.writerow(tmp)I tried adding the full C: Python27 nflscores.csv path to the open statement but that doesn't work. I'm wondering if there's some default setting in Excel that saves it to MyDocuments?