简体   繁体   English

Outlook VSTO 加载项自定义规则/脚本

[英]Outlook VSTO Add-in Custom rule/script

I have a VBA Script which I want to turn into a VSTO add-in for Outlook.我有一个 VBA 脚本,我想把它变成 Outlook 的 VSTO 插件。

In VBA I have a method called在 VBA 中,我有一个方法叫做

Public Sub DruckeAnhaenge(oMail As Outlook.MailItem)

which pops up when I create a rule with "Run a script" then I can select this method.当我使用“运行脚本”创建规则时会弹出它,然后我可以选择此方法。 Which is there called "ThisOutlookSession.DruckeAnhaenge".这就是所谓的“ThisOutlookSession.DruckeAnhaenge”。

Now I created in Visual Studio a VSTO add-in which has exactly the same method, but it doesn't show up anymore.现在我在 Visual Studio 中创建了一个 VSTO 加载项,它具有完全相同的方法,但它不再显示了。

The startup method is called from this add-in (checked it with a MsgBox).从此加载项调用启动方法(使用 MsgBox 对其进行检查)。 So my question is how I can get this method as rule/script as it is in the VBA Editor?所以我的问题是如何将这种方法作为 VBA 编辑器中的规则/脚本?

Here is my whole code from the Add-In.这是我来自插件的完整代码。

Public Class ThisAddIn

    Private Sub ThisAddIn_Startup() Handles Me.Startup
        MsgBox("Add In wird erfolgreich ausgeführt")
    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

    End Sub

    Private Declare Function ShellExecute Lib "shell32.dll" Alias _
        "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String,
        ByVal lpFile As String, ByVal lpParameters As String,
        ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

    Private WithEvents Items As Outlook.Items

    Public Sub DruckeAnhaenge(oMail As Outlook.MailItem)
        On Error Resume Next
        Dim colAtts As Outlook.Attachments
        Dim oAtt As Outlook.Attachment
        Dim sFile As String
        Dim sDirectory As String
        Dim sFileType As String

        sDirectory = "C:\Attachments\"

        'Set colAtts = oMail.Attachments

        If oMail.Attachments.Count Then
            For Each oAtt In oMail.Attachments

                ' This code looks at the last 4 characters in a filename
                sFileType = LCase$(Right$(oAtt.FileName, 4))

                Select Case sFileType

                ' Add additional file types below
                    Case ".xls", ".doc", ".pdf"
                        sFile = sDirectory & oAtt.FileName
                        oAtt.SaveAsFile(sFile)
                        ShellExecute(0, "print", sFile, vbNullString, vbNullString, 0)
                End Select
            Next
        End If
    End Sub
End Class

Outlook doesn't provide any way for assigning COM add-ins to rules. Outlook 不提供将 COM 加载项分配给规则的任何方法。 So, you need to handle corresponding events that OOM provides.因此,您需要处理 OOM 提供的相应事件。 In that case you need to handle the NewMailEx event of the Application class which is fired when a new item is received in the Inbox.在这种情况下,您需要处理 Application 类的NewMailEx事件,当收件箱中收到新项目时会触发该事件。 The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. NewMailEx事件在新邮件到达收件箱时和客户端规则处理发生之前触发。 You can use the Entry ID returned in the EntryIDCollection array to call the GetItemFromID method and process the item.您可以使用EntryIDCollection数组中返回的条目 ID 来调用GetItemFromID方法并处理该项目。 Then you can call the DruckeAnhaenge method and pass the item there.然后您可以调用DruckeAnhaenge方法并将项目传递到那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM