O
Olivier Langlois
Hi,
I wrote a VBA subroutine that is called from an Outlook rule. What the
subroutine does is to look into the MailItem.body to search for certain
keywords and based on the result, move the mailItem in a given folder.
Since I wrote this script, a couple of annoying things happened. First,
I had few other scripts used in Outlook rules but since I wrote the one
accessing the MailItem.body property, I had to lower my Macro security
level from High to Medium because otherwise my macros are deactivated.
Second, everytime my new macro is executed, I get the extremely
annoying Security warning popup window and I would like to get rid of
it. It is written in the Outlook doc:
You can avoid the display of security warnings by deriving all objects,
properties, and methods from the Application object passed in the
OnConnection procedure of the add-in. Outlook trusts only the
Application object passed in the OnConnection procedure of the add-in.
If you create a new Application object- for example, by using the
CreateObject method- that object and any of its subordinate objects,
properties, and methods will not be trusted and the blocked properties
and methods will throw security warnings.
Unfortunatly, I am not able to decrypt the meaning of the last
paragraph. Is there someone who could tell me what I could do with my
VBA script used in a Outlook rule to get rid the security warning?
Thank you,
Olivier Langlois
http://www3.sympatico.ca/olanglois
Here is the code of my macro:
Sub CustomCVSMessageRule(Item As Outlook.MailItem)
Dim BodyStr As String
Dim BranchName As String
Dim BugNumber As String
Dim CommaPos As Integer
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
Set myNameSpace = GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
BodyStr = Item.Body
' Try to find a bug number
BugNumber = FindBugNumber(BodyStr)
If Len(BugNumber) > 0 Then
' Place the e-mail in the bugs subfolder
Set myDestFolder = FindOrCreateFolder(myInbox, "Bugs")
Set myDestFolder = FindOrCreateFolder(myDestFolder, BugNumber)
Else
Set myDestFolder = FindOrCreateFolder(myInbox, "CVS")
BranchName = FindBranchName(BodyStr)
If Len(BranchName) > 0 Then
' Place the mail in CVS subfolder
Set myDestFolder = FindOrCreateFolder(myDestFolder,
BranchName)
End If
End If
Item.Move myDestFolder
End Sub
Function FindBugNumber(inputStr As String) As String
Dim bracketStart As Integer
Dim bracketEnd As Integer
FindBugNumber = ""
bracketStart = InStr(inputStr, "[Bug")
If bracketStart = 0 Then
' There is no bug string
Exit Function
End If
' Skip "[Bug "
bracketStart = bracketStart + 5
bracketEnd = InStr(bracketStart, inputStr, "]")
FindBugNumber = Mid$(inputStr, bracketStart, bracketEnd -
bracketStart)
End Function
Function FindBranchName(inputStr As String) As String
Dim bracketStart As Integer
Dim bracketEnd As Integer
FindBranchName = ""
bracketStart = InStr(inputStr, "BRANCH: ")
If bracketStart = 0 Then
' There is not BRANCH string
Exit Function
End If
' Skip "BRANCH: "
bracketStart = bracketStart + 8
bracketEnd = InStr(bracketStart, inputStr, Chr$(13))
FindBranchName = Mid$(inputStr, bracketStart, bracketEnd -
bracketStart)
End Function
Function FindOrCreateFolder(inputFolder As Outlook.MAPIFolder,
folderName As String) As Outlook.MAPIFolder
Dim curFolder As Outlook.MAPIFolder
For Each curFolder In inputFolder.Folders
If folderName = curFolder.Name Then
Set FindOrCreateFolder = curFolder
Exit Function
End If
Next curFolder
Set FindOrCreateFolder = inputFolder.Folders.Add(folderName)
End Function
Sub TestFindBranchName()
MsgBox FindBranchName(" BRANCH: r11sp" + Chr$(13) + Chr$(10) + "a
toto")
End Sub
I wrote a VBA subroutine that is called from an Outlook rule. What the
subroutine does is to look into the MailItem.body to search for certain
keywords and based on the result, move the mailItem in a given folder.
Since I wrote this script, a couple of annoying things happened. First,
I had few other scripts used in Outlook rules but since I wrote the one
accessing the MailItem.body property, I had to lower my Macro security
level from High to Medium because otherwise my macros are deactivated.
Second, everytime my new macro is executed, I get the extremely
annoying Security warning popup window and I would like to get rid of
it. It is written in the Outlook doc:
You can avoid the display of security warnings by deriving all objects,
properties, and methods from the Application object passed in the
OnConnection procedure of the add-in. Outlook trusts only the
Application object passed in the OnConnection procedure of the add-in.
If you create a new Application object- for example, by using the
CreateObject method- that object and any of its subordinate objects,
properties, and methods will not be trusted and the blocked properties
and methods will throw security warnings.
Unfortunatly, I am not able to decrypt the meaning of the last
paragraph. Is there someone who could tell me what I could do with my
VBA script used in a Outlook rule to get rid the security warning?
Thank you,
Olivier Langlois
http://www3.sympatico.ca/olanglois
Here is the code of my macro:
Sub CustomCVSMessageRule(Item As Outlook.MailItem)
Dim BodyStr As String
Dim BranchName As String
Dim BugNumber As String
Dim CommaPos As Integer
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
Set myNameSpace = GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
BodyStr = Item.Body
' Try to find a bug number
BugNumber = FindBugNumber(BodyStr)
If Len(BugNumber) > 0 Then
' Place the e-mail in the bugs subfolder
Set myDestFolder = FindOrCreateFolder(myInbox, "Bugs")
Set myDestFolder = FindOrCreateFolder(myDestFolder, BugNumber)
Else
Set myDestFolder = FindOrCreateFolder(myInbox, "CVS")
BranchName = FindBranchName(BodyStr)
If Len(BranchName) > 0 Then
' Place the mail in CVS subfolder
Set myDestFolder = FindOrCreateFolder(myDestFolder,
BranchName)
End If
End If
Item.Move myDestFolder
End Sub
Function FindBugNumber(inputStr As String) As String
Dim bracketStart As Integer
Dim bracketEnd As Integer
FindBugNumber = ""
bracketStart = InStr(inputStr, "[Bug")
If bracketStart = 0 Then
' There is no bug string
Exit Function
End If
' Skip "[Bug "
bracketStart = bracketStart + 5
bracketEnd = InStr(bracketStart, inputStr, "]")
FindBugNumber = Mid$(inputStr, bracketStart, bracketEnd -
bracketStart)
End Function
Function FindBranchName(inputStr As String) As String
Dim bracketStart As Integer
Dim bracketEnd As Integer
FindBranchName = ""
bracketStart = InStr(inputStr, "BRANCH: ")
If bracketStart = 0 Then
' There is not BRANCH string
Exit Function
End If
' Skip "BRANCH: "
bracketStart = bracketStart + 8
bracketEnd = InStr(bracketStart, inputStr, Chr$(13))
FindBranchName = Mid$(inputStr, bracketStart, bracketEnd -
bracketStart)
End Function
Function FindOrCreateFolder(inputFolder As Outlook.MAPIFolder,
folderName As String) As Outlook.MAPIFolder
Dim curFolder As Outlook.MAPIFolder
For Each curFolder In inputFolder.Folders
If folderName = curFolder.Name Then
Set FindOrCreateFolder = curFolder
Exit Function
End If
Next curFolder
Set FindOrCreateFolder = inputFolder.Folders.Add(folderName)
End Function
Sub TestFindBranchName()
MsgBox FindBranchName(" BRANCH: r11sp" + Chr$(13) + Chr$(10) + "a
toto")
End Sub