Excel vba call Python script on Mac
How can I launch an external python process from Excel 365 VBA on OSX?
It took me a while, but I figured out how to do it.
Excel 2016 has replaced MacScript() with AppleScriptTask(). This needs to be given an AppleScript file and function to call, and can't, as far as I am aware, be given raw AppleScript commands.
I created an AppleScript file called PythonCommand.scpt which contained something like:
on PythonCommand(pythonScript)
do shell script "/usr/local/bin/python " & pythonScript
end PythonCommand
This AppleScript file needs to be then placed in ~/Library/Application Scripts/com.microsoft.Excel/ (create this folder if it doesn't exist)
Once this is here, the function can be called using:
Dim result As String
result = AppleScriptTask("PythonCommand.scpt", "PythonCommand", pythonScript)
(it insists on returning something - it won't work without this)
A security proviso:
Any Excel macro can call this AppleScript. Macros can do nasty things anyway, but it would be worth putting some protection into it anyway to avoid additional code being executed.
翻译成人话:
mkdir -p ~/Library/Application\ Scripts/com.microsoft.Excel
vim PythonCommand.scpt
i输入以下内容
on PythonCommand(pythonScript)
do shell script "python -c '" & pythonScript & "'"
end PythonCommand
保存
然后在 Excel 新建一个 vba 模块
Sub CallPython()
s = AppleScriptTask("PythonCommand.scpt", "PythonCommand", "print(42)")
MsgBox (s)
End Sub
执行
have fun!
Excel vba call Python script on Mac的更多相关文章
- Python Ethical Hacking - MAC Address & How to Change(2)
FUNCTIONS Set of instructions to carry out a task. Can take input, and return a result. Make the cod ...
- Python Ethical Hacking - MAC Address & How to Change(1)
MAC ADDRESS Media Access Control Permanent Physical Unique Assigned by manufacturer WHY CHANGE THE M ...
- 在Excel VBA中使用SQL到底优势在哪儿
小爬在之前的博文中多次提到,可以在VBA中写SQL来操作Excel文件,实现各类数据处理和分析需求.那么,你可能有这样的疑问:Excel原生的VBA,数据透视表,数据分析功能不够吗,为啥一定要用SQL ...
- Excel VBA中写SQL,这些问题的方法你一定要牢记
小爬之前的文章 [Excel VBA中写SQL,这些问题你一定为此头痛过]中详细讲诉了一些常见的VBA 中使用SQL遇到的问题,这里再补充两个常见的问题场景及对应的解决方案,希望你们看了后能够思路开阔 ...
- 来吧!带你玩转 Excel VBA
来吧!带你玩转 Excel VBA 从错失良机到艰辛的DOS征程,从坎坷购机自学路到转机起程,从爱好到事业,他从一个完全不懂电脑的人到VBA高级应用者,一切全是自学…… 我是罗刚君,来自四川的一个小县 ...
- Python 获取 网卡 MAC 地址
/*********************************************************************** * Python 获取 网卡 MAC 地址 * 说明: ...
- C#调用Excel VBA宏
近日的一系列工作是做网站的营运维护,因此做了大量的支持工具.有Excel中写VBA的,也有直接C#做的工具.有时需要在C#中执行Excel VBA宏,甚至有时还需要在执行了VBA宏之后,获取返回值再进 ...
- java + spring (jython\python\script) Error:SyntaxError: no viable alternative at character '\n'
使用Jython结合java和Python开发功能时,要是遇到如下情况: 2016-03-10 16:16:49 DEBUG [com.freedom.orion.configs.JyhtonConf ...
- 2017-5-29 Excel VBA 小游戏
---恢复内容开始--- 转一个Excel VBA的小游戏,最近对excel有了更深入的了解,功能很强大,也刷新了我对待事情的态度. 一.准备界面 我们先来把游戏界面准备好,选中前4行,行高调成50, ...
随机推荐
- Pycharm关联gitlab(http方式)
Pycharm支持关联gitlab仓库,关联后对远端项目的克隆和提交都很方便.当初笔者在关联时遇到了很多坑,网上也没找到相关解决办法,所以在这里分享下完整的关联过程. 一.安装git 下载地址http ...
- Altium Designer 21.x中文版安装破解教程
Altium Designer 21.x是一款优秀的PCB设计工具,可以原理图设计.电路仿真.PCB绘制编辑.拓扑逻辑自动布线.信号完整性分析和设计输出等功能,为设计者提供了全新的设计解决方案,提高设 ...
- 大数据学习(24)—— Spark入门
在学Spark之前,我们再回顾一下MapReduce的知识,这对我们理解Spark大有裨益. 在大数据的技术分层中,Spark和MapReduce同为计算层的批处理技术,但是Spark比MapRedu ...
- SQL语句(一)基础查询与过滤数据
目录 一.数据库测试表 二.基础查询 1. 获得需要的记录的特定字段 2. 查询常量值 3. 查询表达式 4. 查询函数 5. 起别名 6. 去重 7. CONCAT函数的简单使用 三.过滤数据 大纲 ...
- 庆FastGithub加入.NET Core Community
.NET Core Community .NET Core Community是一个基于并围绕着 .NET 技术栈展开组织和活动的非官方.非盈利性的民间开源社区,提供了很多优秀的 .NET 开源项目. ...
- C作用域
任何一种编程中,作用域是程序中定义的变量所存在的区域,超过该区域变量就不能被访问.C 语言中有三个地方可以声明变量: 在函数或块内部的局部变量 在所有函数外部的全局变量 在形式参数的函数参数定义中 局 ...
- Specify Default JDK on Ubuntu
sudo update-alternatives --config java will produce: Selection Path Priority Status 0 /usr/lib/jvm/j ...
- Linux 开机关机在线求助与指令输入
由于那本书版本稍稍有点早,我就跳过学习第二章第三章了(分别是主机规划和虚拟机安装)下图为在自己电脑上安装好的redhat7 4.1 我们来登入 其中第一行是Linux发行商和发行版本(欸,我的这个怎么 ...
- DVWA(一):关于DVWA的基本介绍
一.关于DVWA的搭建及报错问题: 传送门 上面链接主要解决安装DVWA报错的问题,这里防止自己再去找,所以记一下. (1)安装DVWA需要一个web环境,我实在win2003系统(xss_uploa ...
- XXXMapper.xml中嵌套查询
XXXMapper.xml中嵌套查询 <resultMap id="LiveUserNocticeMap" type="com.fxkj.common.vo.Liv ...