Private WithEvents Items As outlook.ItemsPrivate Sub Application_Startup()
Dim olApp As outlook.Application
Dim objNS As outlook.NameSpace
Set olApp = outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemAdd(ByVal item As Object)
Debug.Print "Im alive!!"
On Error GoTo ErrorHandler
Dim MyAppID, ReturnValue
Dim Msg As outlook.MailItem
Dim vPID As Variant
Dim arr
Dim InstrumentBatch
Dim Instrument
Dim WithinInstrument
Dim html As HTMLDocument: Set html = CreateObject("htmlfile")
If TypeName(item) = "MailItem" Then
Set Msg = item
If Msg.Subject = "Marketplace - Notification" Then
InstrumentBatch = Split(Msg.HTMLBody, "</th></head>")
Instrument = Split(InstrumentBatch(1), "</td></tr>")
UserForm2.Instrument = ""
UserForm2.Direction = ""
UserForm2.Nominal = ""
UserForm2.Rate = ""
UserForm2.Tenor = ""
UserForm2.PV01 = ""
For i = 0 To UBound(Instrument) - 1 Step 1
Instrument(i) = Replace(Instrument(i), "<tr><td>", "|")
Instrument(i) = Replace(Instrument(i), "</td><td>", "|")
WithinInstrument = Split(Instrument(i), "|")
UserForm2.Instrument = UserForm2.Instrument & WithinInstrument(1) & vbNewLine
If InStr(WithinInstrument(2), "receives") Then
WithinInstrument(2) = Replace(WithinInstrument(2), "Nr", "N r")
Else
WithinInstrument(2) = Replace(WithinInstrument(2), "Np", "N p")
End If
UserForm2.Direction = UserForm2.Direction & WithinInstrument(2) & vbNewLine
UserForm2.Nominal = UserForm2.Nominal & WithinInstrument(3) & vbNewLine
UserForm2.Rate = UserForm2.Rate & WithinInstrument(4) & vbNewLine
UserForm2.Tenor = UserForm2.Tenor & WithinInstrument(5) & vbNewLine
UserForm2.PV01 = UserForm2.PV01 & WithinInstrument(6) & vbNewLine
Next
UserForm2.Direction.TextAlign = 3
UserForm2.Nominal.TextAlign = 3
UserForm2.Rate.TextAlign = 3
UserForm2.Tenor.TextAlign = 3
UserForm2.PV01.TextAlign = 3
MsgBox "Notification: Trade done on Marketplace", vbSystemModal + vbExclamation, "Marketplace Trade"
UserForm2.Show vbModeless
End If
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub