首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >COM加载项、Outlook、ItemSend

COM加载项、Outlook、ItemSend
EN

Stack Overflow用户
提问于 2011-01-24 16:08:49
回答 1查看 1.2K关注 0票数 0

我正在尝试编写一个Office2007COM外接程序,它将在发送邮件之前检查一些规则。下面的测试代码可以工作,但我在VS2010中有几个警告,也许有人可以帮助我。

代码如下:

代码语言:javascript
复制
Imports Extensibility
Imports System.Runtime.InteropServices
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.Office.Core
Imports System.Reflection
Imports Microsoft.Win32



<GuidAttribute("B19F59E7-4F71-475C-9531-FB46842E5E5E"), ProgIdAttribute("DODATKI.Connect")> _
Public Class Connect

 Implements Extensibility.IDTExtensibility2
    Dim WithEvents OutlookApplication As Microsoft.Office.Interop.Outlook.Application
 Private applicationObject As Object
    Private addInInstance As Object

    Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
        'MsgBox("Add-in is OnBeginShutdown")
    End Sub

 Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
 End Sub

    Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
        MsgBox("Add-in is OnStartupComplete")
        OutlookApplication = New Outlook.Application
    End Sub

 Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
 End Sub

 Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
        MsgBox("Add-in is OnConnection")
        applicationObject = application
        addInInstance = addInInst

        ' If you aren't in startup, manually call OnStartupComplete.
        If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup) Then _
           Call OnStartupComplete(custom)

 End Sub
    Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles OutlookApplication.ItemSend
        System.Windows.Forms.MessageBox.Show("Hi, You are sending message")
        Dim Msg As Outlook.MailItem
        Msg = Item

        If Trim(Item.Subject) = "" Then
            System.Windows.Forms.MessageBox.Show("Cannot send message with an empty subject!!!")
            Cancel = True
        End If
    End Sub
End Class

警告:

代码语言:javascript
复制
1) On Msg = Item
Warning 1 Implicit conversion from 'Object' to Microsoft.Office.Interop.Outlook.MailItem'
2) On Item.Subject
Warning 2 Implicit conversion from 'Object' to 'String'
3) On Item.Subject
Warning 3 Late bound resolution; runtime errors could occur
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-24 17:23:13

大约1:

代码语言:javascript
复制
Msg = CType(Item, Outlook.MailItem)

关于2和3:

代码语言:javascript
复制
If Trim(Msg.Subject)

另一个建议是打开选项显式和选项严格,即在每个文件的顶部添加如下内容

代码语言:javascript
复制
Option Explicit On
Option Strict On
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4779856

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档