我有一个会议/约会项目,并为此表格提供了一个设置的类别。我现在希望能够决定是否在日历中输入哪个。
我是VBA的初学者,并且有一段代码可以找到我的特定类别,这很有效。
Sub testSearch()
Dim olApp As Outlook.Application
Dim objNS As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim olMail As Outlook.MailItem 'Search only for MailItem
Dim inboxItem As Object ' Object search all types MailItem, MeetingItem or AppointItem...
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
If LCase$(inboxItem.Categories) = "testword" Then
Debug.Print "Categories ok"
Else
Debug.Print "Categories error"
End If
'Print for testing all Items in the inbox
'Debug.Print msg.Subject
Next
End Sub
现在,我的想法是,当我找到该项目时,我想查看约会并能够决定是否要将其添加到日历中。
首先,我建议使用Instr
函数而不是比较字符串。 Categories字符串可能包含其他标记,而不仅仅是您的单个标记。