如何从Excel / VBAmacros中使用环境variablespath到Python安装?

这工作:

Path = "c:\Python27\python.exe" File = ThisWorkbook.Path & "\Positionly-API-Keyword-Script.py" 

这不起作用:

 Path = "%systemdrive%\Python27\python.exe" File = ThisWorkbook.Path & "\Positionly-API-Keyword-Script.py" 

什么给

我只是想让我的macros更加灵活,以便它总能findPython 2.7,如果它安装在默认的目录中的(这可能是也可能不是C 🙂

理想情况下,我想直接将variables/path传递给Python,使其在error handling方面更加灵活和严格。 我只是不知道VBA做我想做的事情!

 path=environ("Systemdrive") & "\python27\python.exe" 

您可以使用Environ函数来获取操作系统variables。