python执行vba处理excel_通过Excel/VBA运行Python脚本

Dim objShell

Dim command as String 'use this declaration type for VBA (Access/Excel)

'Dim command 'use this declaration type for VBS (Script), instead of the direct declaration like as "As String"

command = Chr(34) & "C:\Users\John Doe\python.exe" & Chr(34) & " " & Chr(34) & "C:\Users\John Doe\" & "\roto.py" & Chr(34)

Set objShell = CreateObject("WScript.Shell")

objShell.Run command, 1, True

'Settings for WindowStyle:

' 0 Hide the window (and activate another window.)

' 1 Activate and display the window. (restore size and position) Specify this flag when displaying a window for the first time.

' 2 Activate & minimize.

' 3 Activate & maximize.

' 4 Restore. The active window remains active.

' 5 Activate & Restore.

' 6 Minimize & activate the next top-level window in the Z order.

' *** 7 Minimize. The active window remains active.

' 8 Display the window in its current state. The active window remains active.

' 9 Restore & Activate. Specify this flag when restoring a minimized window.

' 10 Sets the show-state based on the state of the program that started the application.

顺便说一句,您可以简单地使用2个引号将引号插入字符串变量,就像我在以前的源代码中使用的那样。例如,StrVariable=""""给出结果"。那么命令行的字符串是:

command = """%USERPROFILE%\python.exe"" ""%USERPROFILE%\roto.py"""

结果是:

"C:\Users\John Doe\python.exe" "C:\Users\John Doe\roto.py"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值