Operating system:: Windows 10
Outlook version: 2021
Email type or host: Pop
Outlook version: 2021
Email type or host: Pop
I have 3 QuickBooks files for 3 different companies, we are sending the sales orders and invoices from the same outlook application, I have 3 email accounts where I'm sending the emails from, each account is being used for a different company, I've developed a macro to detect which email account to use based on the subject, every time we create an email we hit the macro button to run it. is it possible to get the macro to run automatically when we hit the send button?
Sub Try()
Dim myInspector As Outlook.Inspector
Dim MItem As MailItem
Dim outaccount As Outlook.Account
Set myInspector = Application.ActiveInspector
Set MItem = myInspector.CurrentItem
'Blanc Home
If Right(MItem.Subject, 10) Like "Blanc Home" Then
If Left(MItem.Subject, 3) Like "Sal" Then
MItem.SentOnBehalfOfName = "Orders @ Blanc Home"
ElseIf Left(MItem.Subject, 3) Like "Inv" Then
MItem.SentOnBehalfOfName = "Billing @ Blanc Home"
ElseIf Left(MItem.Subject, 3) Like "Sta" Then
MItem.SentOnBehalfOfName = "Billing @ Blanc Home"
End If
Set outaccount = Application.Session.Accounts.Item("Blanc Home")
MItem.SendUsingAccount = outaccount
Else
End If
'Distinctive Creations
If Right(MItem.Subject, 9) Like "Creations" Then
If Left(MItem.Subject, 3) Like "Sal" Then
MItem.SentOnBehalfOfName = "Orders @ Distinctive C"
ElseIf Left(MItem.Subject, 3) Like "Inv" Then
MItem.SentOnBehalfOfName = "Billing @ Distinctive C"
ElseIf Left(MItem.Subject, 3) Like "Sta" Then
MItem.SentOnBehalfOfName = "Billing @ Distinctive C"
ElseIf Left(MItem.Subject, 5) Like "FW: I" Then
MItem.Subject = Replace(MItem.Subject, "FW: ", "")
MItem.SentOnBehalfOfName = "Billing @ Distinctive C"
ElseIf Left(MItem.Subject, 6) Like "FW: Sa" Then
MItem.Subject = Replace(MItem.Subject, "FW: ", "")
MItem.SentOnBehalfOfName = "Orders @ Distinctive C"
End If
Set outaccount = Application.Session.Accounts.Item("DC Info")
MItem.SendUsingAccount = outaccount
Else
End If
'Fern Home
If Right(MItem.Subject, 10) Like "Fern Home." Then
If Left(MItem.Subject, 3) Like "Sal" Then
MItem.SentOnBehalfOfName = "Orders @ Fern Home"
ElseIf Left(MItem.Subject, 3) Like "Inv" Then
MItem.SentOnBehalfOfName = "Billing @ Fern Home"
ElseIf Left(MItem.Subject, 3) Like "Sta" Then
MItem.SentOnBehalfOfName = "Billing @ Fern Home"
End If
MItem.Subject = Replace(MItem.Subject, "Home.", "Home")
Set outaccount = Application.Session.Accounts.Item("Fern Home")
MItem.SendUsingAccount = outaccount
Else
End If
End Sub
Sub Try()
Dim myInspector As Outlook.Inspector
Dim MItem As MailItem
Dim outaccount As Outlook.Account
Set myInspector = Application.ActiveInspector
Set MItem = myInspector.CurrentItem
'Blanc Home
If Right(MItem.Subject, 10) Like "Blanc Home" Then
If Left(MItem.Subject, 3) Like "Sal" Then
MItem.SentOnBehalfOfName = "Orders @ Blanc Home"
ElseIf Left(MItem.Subject, 3) Like "Inv" Then
MItem.SentOnBehalfOfName = "Billing @ Blanc Home"
ElseIf Left(MItem.Subject, 3) Like "Sta" Then
MItem.SentOnBehalfOfName = "Billing @ Blanc Home"
End If
Set outaccount = Application.Session.Accounts.Item("Blanc Home")
MItem.SendUsingAccount = outaccount
Else
End If
'Distinctive Creations
If Right(MItem.Subject, 9) Like "Creations" Then
If Left(MItem.Subject, 3) Like "Sal" Then
MItem.SentOnBehalfOfName = "Orders @ Distinctive C"
ElseIf Left(MItem.Subject, 3) Like "Inv" Then
MItem.SentOnBehalfOfName = "Billing @ Distinctive C"
ElseIf Left(MItem.Subject, 3) Like "Sta" Then
MItem.SentOnBehalfOfName = "Billing @ Distinctive C"
ElseIf Left(MItem.Subject, 5) Like "FW: I" Then
MItem.Subject = Replace(MItem.Subject, "FW: ", "")
MItem.SentOnBehalfOfName = "Billing @ Distinctive C"
ElseIf Left(MItem.Subject, 6) Like "FW: Sa" Then
MItem.Subject = Replace(MItem.Subject, "FW: ", "")
MItem.SentOnBehalfOfName = "Orders @ Distinctive C"
End If
Set outaccount = Application.Session.Accounts.Item("DC Info")
MItem.SendUsingAccount = outaccount
Else
End If
'Fern Home
If Right(MItem.Subject, 10) Like "Fern Home." Then
If Left(MItem.Subject, 3) Like "Sal" Then
MItem.SentOnBehalfOfName = "Orders @ Fern Home"
ElseIf Left(MItem.Subject, 3) Like "Inv" Then
MItem.SentOnBehalfOfName = "Billing @ Fern Home"
ElseIf Left(MItem.Subject, 3) Like "Sta" Then
MItem.SentOnBehalfOfName = "Billing @ Fern Home"
End If
MItem.Subject = Replace(MItem.Subject, "Home.", "Home")
Set outaccount = Application.Session.Accounts.Item("Fern Home")
MItem.SendUsingAccount = outaccount
Else
End If
End Sub