VBA code that runs on .xlsm
or .docm
files, installs python, and executes given python code.
Well, basically the code can be used in .xlsm
or .docm
files as macros for workbooks, sheets, modules and etc.
To execute your custom code you have to use it in the next way:
-
The code have to work in python.
-
The first line of the code is just like regular python.
-
After the first line, every line have to be separated by
|
character. -
If the line starts with
TAB
s orSPACE
s you have to add them after the|
character. -
All the code have to be in one line.
-
The line to change is:
python_script
is a variable that stores the code, so it shouldn't be changed, but the content of the string can be changed for your needs.
The concept is very simple - just use python triple quotes character to place in it the code and replace all the new line characters (\n
) with |
.
I have already prepared a python script that does it for you, but you can create your own script to format it with better user interface.