2009년 10월 16일 금요일

Outlook에서 Visual Basic Script 사용하기

어제 하루 종일 이걸로 고생했네.

내가 원하는 건, MS Outlook 에서 새 메일이 왔을 때,
어떤 조건을 만족하면 메일을 열어주는 것이지.

근데 이거 하기가 왜케 힘들어.

가장 도움이 되었던 링크.
응용 프로그램에 대한 Visual Basic을 사용하여 Outlook 2000에서 사용자 지정 규칙을 만드는 방법
http://www.w3schools.com/VBscript/func_instr.asp

여긴 그냥 참고할 만한 링크.
Automating Outlook E-mail Handling with VBA
http://www.outlookcode.com/article.aspx?id=40
http://www.dotnetmonster.com/Uwe/Forum.aspx/vs-net-office/1927/how-to-create-a-custom-RoleAction-for-outlook-2007
http://support.microsoft.com/kb/324568

결론,

Public WithEvents myOlItems As Outlook.Items

Public Sub Application_Startup()
' Reference the items in the Inbox. Because myOlItems is declared ' "WithEvents" the ItemAdd event will fire below.
myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)
Dim msg As MailItem
If TypeName(Item) = "MailItem" Then
msg = Item
If msg.Attachments.Count > 0 Then
msg.Display()
ElseIf msg.Importance = olImportanceHigh Then
msg.Display()
ElseIf InStr(1, msg.To, "내 메일주소", 1) <> 0 Then
msg.Display()
End If
End If
End Sub

수정: 2009.12.2
소스 이쁘게 하고, VBS에서 IF문은 예전처럼(nested)쓰면 안될거 같어서 바꾸고~

댓글 없음: