使用VBA中的变量作为命令行参数运行Python

时间:2017-12-20 14:30:22

标签: python vba outlook outlook-vba

我正在尝试在Outlook中构建一个宏来执行以下操作: - 从电子邮件中获取突出显示的字符串 - 通过python脚本运行字符串 - 将脚本中返回的值保存为变量 - 在输入框中显示结果

到目前为止,我已对此进行了编码:

Sub showseltext()

Dim msg As Outlook.MailItem
Dim insp As Outlook.Inspector

If Application.ActiveInspector Is Nothing Then
    If Application.ActiveExplorer.Selection.Count = 1 Then
        If Application.ActiveExplorer.Selection.Item(1).Class = olMail Then
            Set msg = Application.ActiveExplorer.Selection.Item(1)
        End If
    Else
        'too many items selected
        MsgBox "Please select one email"
    End If
Else
    Set insp = Application.ActiveInspector
    If insp.CurrentItem.Class = olMail Then
        Set msg = insp.CurrentItem
    End If
End If

If msg Is Nothing Then
    MsgBox "could not determine the mail item"
Else
    If msg.GetInspector.EditorType = olEditorWord Then
        Set hed = msg.GetInspector.WordEditor
        Set appWord = hed.Application
        Set Rng = appWord.Selection
        RetVal = Shell("C:\python27\python.exe " & "C:\Users\bob\Documents\proofpoint-url-decoder-master\proofpoint-url-decoder-master\decode.py" & "Rng")
        test = InputBox(Rng, "Cleaned ProofPoint URL:", RetVal)
    End If
End If
End Sub

输出数据只是一串数字,每次运行时都会更改。 python代码正常工作,为什么这不起作用?

此外,如果我无法定义python的版本,并且只能通过CMD运行python命令,那将是首选!

0 个答案:

没有答案