Python With VBA ! Run python via VBA
New features, with many changes from 5.x
- Create new RunPy
- Require
PyServer(1.0 for PyWVBA 6.0) - Added cache value
- Huge Performance improves from 5.x
- Require
- Added some server function like
ClearPyServer()- Clear all variable cached - Don't need to create logfile or codefile
- Keep 5.4
RunPy()and renamed it toRunPyOld() - ⚠ Warning:
PyServer 1.0using localhost with port :9812
Lower Version is tested privately; some versions are publicly released, but they are pre-release. They're outdated, unsecure and unstable, so please use only versions 5.2 or above.
- Install python (Any version, NOTE: Checks Add python to path when start setup)
- Install PyWimVBA to your vba project (Install .bas file and see here )
-
StartPyServer(Optional: pythonPath = "python",Optional useCustomPyServer: False,Optional : silent=false): StartsPyServer(PyServer supports only single server)silent=truewill hide command prompt ofPyServer. SetuseCustomPyServerto path of your PyServer (can use in offline or a older pyserver) -
EndPyServer(Optional deletePyServer: True)- A server doesn't close automatically with VBA, so you need to close it before end VBA code . UsedeletePyServer=Falseto keep your PyServer to reuse inStartPyServer(Not recommend) -
CheckPyServer()- Check a or any server is running. -
ClearPyServer()- BecausePyServersupport only one server, you can use this function to clear cached data like value,etc... -
RunPy(code)- Simply run a code of python, split new line with;; -
LoadPy(file,[iline = False])- Load a python file and convert it to PyWimVBA Syntax- For example, it'll convert this file code
examplefile.pyimport time time.sleep(5)- To
import time;time.sleep(5) - APPLY TO USE:
RunPy(LoadPy("mycodefile.anyextension"))
-
RunPyOld(code,[pythonPath = "python"] , [newengine = False], [ keepFileData = False] , [UseDebug = False]) -
Code splitting by ";;" , e.x :
import time;;time.sleep(5) -
[Optional] newengine : Improve performance, doesn't need to create logfile - still create code file . But it's will show up a cmd splash - doesn't work with UseDebug
-
[Optional] keepFileData: Keep the output file and code file after finishing execution.
-
[Optional] UseDebug: Show cmd that runs python code and keep it alive with it's output [Use debug to catch errors, the output file may not catch them. So when debug is enabled, Output file does nothing.
-
E.x :
MsgBox RunPy("Welcome to \'Python With VBA!\'")