pythonvba

Running Python script from VBA nothing happens, but when I run it from python.exe, it works


I'm running Python scrpit from VBA. The result should be a filled cell in Exel file. I tried using this VBA command:

RetVal = Shell("""C:\Python27\python.exe""" & " " & """M:\Analysis\PythonScripts\MySript.py""", vbHide)

But nothing happens as the result. However, if I run this scipt from python.exe directly, it works fine. The cell in Excel file is filled with a value. Which brings me to conclusion that something is wrong with VBA code.

Update

Fragment of Python Script:

ExcelApp = win32com.client.GetActiveObject("Excel.Application")
wb = ExcelApp.Workbooks('File1.xlsm')
sheet = wb.Worksheets(u'Result')
cell = sheet.Range('B1')
cell.Value = result

Solution

  • I think that if you're running VBA from File1.xlsm this causes conflict between VBA and Python..like file sharing violation/permission denied because now VBA AND Python are trying to control the file at the same time. Try running the VBA from another file that is NOT the target file and let's see how that goes.