2011-01-24 4 views
0

메일을 보내기 전에 몇 가지 규칙을 확인하는 Office 2007 COM 추가 기능을 작성하려고합니다. 아래의 테스트 코드는 작동하지만 VS2010에서는 여러 가지 경고가 표시됩니다. 아래COM ADD-in, Outlook, ItemSend

코드 :

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 

경고 :

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 

답변

0

약 1 :

Msg = CType(Item, Outlook.MailItem) 

약 2와 3 :

If Trim(Msg.Subject) 

또 다른 제안은 Option Explicit과 Option Strict를 켜는 것입니다. 즉, 각 파일의 맨 위에는

+0

과 같은 것을 추가하십시오. 고맙습니다. 지금은 괜찮습니다. 어쩌면 당신은 쉼표를 포함하는 폴더를 여는 방법을 알고 있습니다. 쉘 ("explorer.exe \\ server \ path to, folder", vbHide) 또는 Shell ("cmd/c start \\ server \ 경로, 폴더 ", vbHide) – Marcin

+0

안녕하세요 Marcin. 귀하의 질문에 대한 답변이 있으면 제 대답을 "수락 된"것으로 간주 할 수 있습니다. 또한 새로운 질문으로 의견을 다시 나눌 수 있습니다. 답을 얻을 수있는 더 좋은 기회입니다. –

관련 문제