Automate Spell Check on MailItem.Send() ???

B

Brian McCullough

Hello,

I have inherited an Outlook Addin which is currently working for Outlook XP.
The current add in is really simple. It adds a custom button to the
"Standard" toolbar for a MailItem's Inspector and, when clicked, this button
modifies the email message slightly and then sends it. The problem is, the
code use's the MailItem's .Send() method to send the message and, because
many of the users in the company use Outlook's editors (i.e. RichText or
HTML) to create the email messages, the Spell Checker is not launched when
the message is sent (even if the appropriate settings have been configured
in the Tools > Options > Spelling tab).

I have been asked to get some sort of spell checking to work with this
addin. The addin is written in vb.net and I have access to the Redemption
library.

After attempting a few solutions using Word as the "spell check hosting
engine" (as in this MSDN article:
http://msdn2.microsoft.com/en-us/library/aa203681(office.11).aspx) and
automating the "click" of the regular Send button, I have been unsuccessful.

I am really close using something where I automate the "click" of the
Inspector's Tools > Spelling command (looks similar to this):


Private Sub HandleMyButton()

Dim objMailItem as MailItem 'this is set and initialized up top

'checks in place to check for Word mail up here...the rest assumes Outlook
mail editor

Dim ctlSpellCheck As CommandBarControl
Dim cbrMenuBar As CommandBar

Set cbrMenuBar = m_objInsp.CommandBars("Standard")

'i know there is a better way to get this control, but I havent downloaded
Outlook Spy again to verify the ID of the Spelling menu item
Dim ctlTmp As CommandBarControl
For Each ctlTmp In cbrMenuBar.Controls
If ctlTmp.Type = msoControlButton Then
If ctlTmp.Caption = "&Spelling..." Then
Set ctlSpellCheck = ctlTmp
Exit For
End If
End If
Next

'a "Spell Check has Completed" message box is shown after Outlooks Spell
Checker has run and NOT BEEN CANCELED...
ctlSpellCheck.Execute

objMailItem.Subject = "MODIFIED MESSAGE" & objMailItem.Subject

objMailItem.Send()

End Sub


There are a few minor problems with this...

1. When I use the Spelling menu item's Execute method, the spell checking
runs fine, but after the spell check has been completed (not canceled), I
get a message stating along the lines of "The spell check has completed".
This same message that you see after spell checking has completed during
regular spell checking functionality (i.e. if you choose Tools > Spelling
menu item on the message yourself). This message isnt shown if I were to
click the regular "Send" button.

2. The spell checking dialog has a "Cancel" button on it, but when I click
this button, I have no way of handling this condition. One thing I do know
is that I don't get the message dialog from #1 above. When I click the
Cancel button, the code just keeps on going and sends the message. However,
when I press Cancel, I'd like to be able to handle this

Is there ANY way possible to determine if the user clicked the "Cancel"
button during the spell check? For example, can I write some low level code
that can hook into the spell check window shown by Outlook? Perhaps there
is a Win32 API method that I could use to determine if the dialog in #1
above was shown, which would indicate that the user did NOT cancel the spell
check??? I know it's a long shot, but I wanted to see if anyone had any
ideas on this...

TIA!!!
 
K

Ken Slovak - [MVP - Outlook]

The only thing I can think of is to find the spelling window using something
like FindWindow() and then hook into its Windows message queue. That way you
can intercept messages directed at that window and check for mouse clicks
and such. How you'd determine all that and how to determine that a click was
on the Cancel button is something you'd also have to determine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top