Below is a Python code, it is suppose to Run a VBA macro, but there seems to be a error on the Win 7 side.
import win32com.client xl=win32com.client.Dispatch(“Excel.Application”) xl.Workbooks.Open(Filename=”C:MYFOLDERNAME”,ReadOnly=0) xl.Application.Run(“py_counter_test”) xl.Workbooks(1).Close(SaveChanges=1) xl.Application.Quit() xl=0
This the error message I get in the script editor for Python is:
com_error:(-2147352567,’Exception occured’,(0,”Microsoft excel’, Excel cannot access ‘MYFOLDERNAME,, The document may be read-only or encrypted,”, ‘xlmain11.chm.,0,-2146827284),none)
I know I have not encrypted the folder, it is simply a “New Folder” in C: and re-named.
It is a test folder in C: to test the code
Name of Folder in Drive C:
C:MYFOLDERNAME
;
Name of workbook is:
PY-COUNTER.xls
;
Name of VBA macro is:
py_counter_test
;
Excel version: 2010
OS: Win 7 pro
Latest Python version: 3.7
PyScripter (latest version)
Thanks
I do use .bat scripts to Run .py scripts. The .bat script is run by VBA.
VBA-bat-py works, but not the other way round it seems