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, ...
随机推荐
- PL SQL Developer 13连接Oracle数据库并导出数据
下载 并安装 PL SQL Developer 13,默认支持中文语言 ============================= 注册码: product code: 4vkjwhfeh3ufnqn ...
- 第一篇 -- Jmeter的安装下载
参考链接:https://blog.csdn.net/wust_lh/article/details/86095924 本篇介绍的是在Windows下安装Jmeter. 一.下载Jmeter 官网下载 ...
- 15Java进阶 进程
1 线程控制 t.join():让主线程进入线程池,等待t执行完才执行. t.sleep():让线程阻塞,休眠一段时间,休眠结束后进入就绪状态.不会释放锁. t.yield():让线程让出CPU,从运 ...
- 对一个sql的分析
select * FROM LPEdorItem a, LCCont b, LPEdorApp c WHERE a.edoracceptno = c.edoracceptno and a.ContNo ...
- HttpRunner3源码阅读: 1. 目录结构分析
初衷 身处软件测试行业的各位应该都有耳闻HttpRunner 开源测试工具/框架(接口测试),作者博客 为什么出这系列? 不少测试同行都建议阅读HttpRunner,源码学习其设计思想. 社区当下Py ...
- 记一次针对excel导出的优化
最近发现我们系统导出excel文件时由于是导出百万级数据导出,速度过慢并且内存占用多,故进行了下面的一次优化. 我们使用apache的poi进行excel文件操作 主要耗时: 1.从数据库得到需要导出 ...
- 简单的Postman,还能玩出花?
Postman是一款我们在工作中使用频率非常高的API调试工具,估计很多童鞋在使用它时也比较粗暴,填好接口地址.参数,直接send就完事了,估计大家要说了,这么简单的东西还能玩出什么花来.今天就和大家 ...
- 并发编程——认识java里的线程
本文系作者 chaoCode原创,转载请私信并在文章开头附带作者和原文地址链接. 违者,作者保留追究权利. 前言 并发编程在我们日常开发中是时时刻刻都有在用的,只不过大部分的代码底层已经帮我们去做了一 ...
- IntelliJ IDEA常用的快捷键积累总结
.personSunflowerP { background: rgba(51, 153, 0, 0.66); border-bottom: 1px solid rgba(0, 102, 0, 1); ...
- SpringCloud升级之路2020.0.x版-13.UnderTow 核心配置
本系列代码地址:https://github.com/HashZhang/spring-cloud-scaffold/tree/master/spring-cloud-iiford Undertow ...