Code working fine in Outlook 2010 but not 2003

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I recently asked a question on these forums to warn if you are sending card numbers via email, and Graham Mayor kindly provided the below code. This worked nicely on Outlook 2010, however when I tried to use it on Outlook 2003 it doesnt appear to work.
Ive had a look around and people have mentioned using late binding to get around this issue. Ive had no success in sorting this out myself, so any assistance would be appreciated. Obviously if there is an easier way to sort this out, that would be great.
(Unfortunately upgrading is not a possibility!)<br/>

As I mentioned it worked on Outlook 2010 with VBA 7 (with Microsoft Office 14 Object Library) but not on Outlook 2003 with VBA 6.5 and object library 11.


Private Sub Application_ItemSend _<br/>
(ByVal Item As Object, Cancel As Boolean)<br/>
Dim strMsg As String<br/>
Dim i As Long<br/>
Dim strtext As String<br/>
If AutomateReplyWithSearchString = True Then<br/>
Cancel = True<br/>
strMsg = "This message contains card or account numbers. Please remove before sending!"<br/>
MsgBox strMsg, _<br/>
vbExclamation + vbSystemModal, "Content Warning"<br/>
End If<br/>
Item.Display<br/>
Set Item = Nothing<br/>
End Sub
and in an ordinary module, insert the following function code
Function AutomateReplyWithSearchString() As Boolean<br/>
Dim olInspector As Outlook.Inspector<br/>
Dim olObject As Object<br/>
Dim olItem As Outlook.MailItem<br/>
Dim wdDoc As Object<br/>
Dim strItem As String<br/>
Dim bFound As Boolean<br/>
Dim strMsg As String<br/>
Dim oRng As Range<br/>
Dim i As Long<br/>
Dim vFindText As Variant<br/>
<br/>
vFindText = Array("[0-9]{4} [0-9]{4} [0-9]{4} [0-9]{4}", "[0-9]{5} / [0-9]{4}")<br/>
<br/>
Set olInspector = Application.ActiveInspector<br/>
Set olObject = olInspector.CurrentItem<br/>
<br/>
If olObject.MessageClass = "IPM.Note" And _<br/>
olInspector.IsWordMail = True Then<br/>
Set olItem = olInspector.CurrentItem<br/>
Set wdDoc = olInspector.WordEditor<br/>
For i = 0 To UBound(vFindText)<br/>
Set oRng = wdDoc.Range<br/>
With oRng.Find<br/>
Do While .Execute(FindText:=vFindText(i), MatchWildcards:=True) = True<br/>
AutomateReplyWithSearchString = True<br/>
Exit For<br/>
Loop<br/>
End With<br/>
Next i<br/>
End If<br/>
Set olInspector = Nothing<br/>
Set olObject = Nothing<br/>
Set wdDoc = Nothing<br/>
Set olItem = Nothing<br/>
End Function<br/>

Thanks in anticipation

View the full article
 
Back
Top