Please help..
I am trying to create an outlook script that will parse the subject line of emails coming from a particular source and organize them, by the ticket number present in the subject line. However, VB is sucking the life out of me on the error below
I am getting a Compile Error: Object Required on the line
Dim subjectLine as String
Set subjectLine = Item.Subject.
If I take the same MailItem (Item) object and pass the Subject property to the MsgBox()
it works...So I am beat on this one bad.
Please view the complete script below...Any and all the help will be greatly appreciated.
Sub CustomMailMessageRule(Item As Outlook.MailItem)
Const folderInbox = 6
Const ticketsFldName = "tickets"
Const nutrioFldName = "nutrio"
Dim objFolder As Outlook.Folder
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(folderInbox)
Dim ticketsFolder As Outlook.Folder
Dim nutrioFolder As Outlook.Folder
ticketsFolder = objFolder.Folder(ticketsFldName)
If (ticketsFolder Is Nothing) Then
ticketsFolder = objFolder.Folders.Add(ticketsFldName)
nutrioFolder = ticketsFolder.Folders.Add(nutrioFldName)
ElseIf (nutrioFolder Is Nothing) Then
nutrioFolder = ticketsFolder.Folders.Add(nutrioFldName)
End If
Dim subjectLine As String
Set subjectLine = Item.Subject
Set begIndexHash = InStr(0, "#", subjectLine)
Set endIndexColon = InStr(0, ":", subjectLine)
Dim ticketNumber As String
If (begIndexHash = 0 Or endIndexColon = 0) Then
Return
Else
Set ticketNumber = Mid$(subjectLine, begIndexHash + 1, (endIndexColon - begIndexHash) - 1)
End If
Set ticketNewFolder = nutrioFolder.Folders.Add(ticketNumber)
Item.Move (ticketNewFolder)
End Sub