How to use more than one "Application_ItemSend" in VBA script for Outlook.
I want both of these scripts to run before I send an email; however, a duplicate command is causing an error message. I really don't know VBA, just enough to copy/paste.
Grammar Check with Spelling
'Occurs before sending email
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objMail As Outlook.MailItem
Dim objMailDocument As Word.Document
Dim objWordApp As Word.Application
Dim strMsg As String
Dim nAnswer As Integer
If TypeOf Item Is MailItem Then
Set objMail = Item
Set objMailDocument = objMail.GetInspector.WordEditor
Set objWordApp = objMailDocument.Application
'Ask you if to spell check
strMsg = "Do you want to spell check the email right now?"
nAnswer = MsgBox(strMsg, vbQuestion + vbYesNo, "Spell Check")
If nAnswer = vbYes Then
'Start spell check
If objWordApp.Options.CheckGrammarWithSpelling = True Then
objMailDocument.CheckGrammar
Else
objMailDocument.CheckSpelling
End If
End If
End If
End Sub
And then this Category script.
'Categorize Sent Items
'Place in ThisOutlookSession
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeOf Item Is Outlook.MailItem And Len(Item.Categories) = 0 Then
Set Item = Application.ActiveInspector.CurrentItem
Item.ShowCategoriesDialog
End If
End Sub
OutlookVBA
Last Comment
David Bigelow
8/22/2022 - Mon
Norie
David
Combine both sets of code in the same event.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Dim objMail As Outlook.MailItem Dim objMailDocument As Word.Document Dim objWordApp As Word.Application Dim strMsg As String Dim nAnswer As Integer If TypeOf Item Is MailItem Then Set objMail = Item Set objMailDocument = objMail.GetInspector.WordEditor Set objWordApp = objMailDocument.Application 'Ask you if to spell check strMsg = "Do you want to spell check the email right now?" nAnswer = MsgBox(strMsg, vbQuestion + vbYesNo, "Spell Check") If nAnswer = vbYes Then 'Start spell check If objWordApp.Options.CheckGrammarWithSpelling = True Then objMailDocument.CheckGrammar Else objMailDocument.CheckSpelling End If End If End If If TypeOf Item Is Outlook.MailItem And Len(Item.Categories) = 0 Then Set Item = Application.ActiveInspector.CurrentItem Item.ShowCategoriesDialog End IfEnd Sub
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
Combine both sets of code in the same event.
Open in new window