Outlook 2007 Spell Checking?

B

Brian McCullough

Hello,

Are there any improvements to the Outlook Object Model that allow you to
more easily work with Spell Checking....Or at least have Outlook function
the same whether you use MailItem.Send() or actually click the Send button?
 
B

Brian McCullough

Ken,

Thanks for your response.

I have read that in Outlook 2007, Word is used as the email editor, even if
you haven't installed Word. If Word is not installed, a subset of it is
installed in order to compose email messages. I understand they wanted to
get rid of the Outlook email editor so that they (Office Development Team)
didn't have to maintain two codebases.

When using Word as the email editor for Outlook 2002 (Office XP), when you
write code using the MailItem.Send() method, and you have the "Always check
spelling before sending" option selected in Outlook, the Word spell checker
is launched (it is not if you use Oulook as the email editor).

It looks like in Outlook 2007, if you have the same code executing (i.e.
MailItem.Send()), the spell checker is NOT launched (eventhough Word is the
email editing program - since there is no more "Outlook editor").

My question is, how are we to make sure that spell checking gets run (using
the provided spell checking tools - not custom tools) if we are automating
the send action of the email ??? In my scenario, I have an addin in which a
"Custom Send" button is added to the Standard toolbar (in 2007, it is loaded
to the "Add-Ins" tab. This "Custom Send" button modifies the message only
slightly, then uses the MailItem.Send method to send the message. When the
message is sent, I'd like any normal pre-processing of the message, such as
spell checking (if the option is selected) to run. Is there a way in 2007
to get the Send action to occur with all the "normal" send rules? For
example, perhaps with the new security model in place, we can now automate
the click of the "Send" button on the mail item's inspector?

From an end user standpoint, if they have checked that spell checking always
be run, then it should run when they initiate a "send" action. And it seems
to me that this is pretty common funnctionality being asked for. I have
seen similar posts for Outlook 2002 and 2003 posted over the last few years.

I understand that someone could be writing code that automates the send
action without any user interaction - for exmaple as a windows service, in
which case you wouldn't want a spell checking dialog displayed, but in the
case where a user is interacting with the message, we should have the
ability to make sure all the normal "send" processing occurs.

If there is no way in 2007 to do this, is there a way to funnel this up to
the Office Development Team to see that they expose this functionality in a
later release or service pack?

TIA!!!

Brian
 
K

Ken Slovak - [MVP - Outlook]

Actually the subset of Word that's used as the email editor is used whether
or not the full Word 2007 is installed. You do get more functionality if you
were to use the Word object model if Word is installed, but the end result
is no more Outlook email editor.

You can force a spell check using code. The presumption is that when using
code to send items that no user interaction is required or wanted, so
normally the spell check will not run.

However, if you get a handle to the email's Inspector you can get the
WordEditor object, which is a Word.Document object. You then can use the
Document.CheckSpelling() method to force a spell check before you send the
email using code. You have to save the email first before you send it.

Here's a quickie VBA sample of how to do that:

Sub SpellIt()
Dim oMail As Outlook.MailItem
Dim oDoc As Word.Document

Set oMail = Application.ActiveInspector.CurrentItem
Set oDoc = Application.ActiveInspector.WordEditor

oMail.Save 'save the item so it is in the Outlook data store

oDoc.CheckSpelling

oMail.Save 'persist any spelling changes

oMail.Send
End Sub

You can also call the grammar checker the same way.
 
B

Brian McCullough

OK..I will try that tomorrow (heading out of the office for today), but one
question that maybe you can answer before I have to test for it...Does the
call to CheckSpelling initiate the user interface for the spell checker, or
does this method only call the method that returns a ProofreadingErrors
collection (or similar type of collection) that I would programatically have
to handle?

Thanks!!

-Brian
 
K

Ken Slovak - [MVP - Outlook]

You get the UI.

One thing to check and I'm not sure if it's my playing around or a gotcha.

I tested similar code in VSTO and a shared addin using C# and in all cases
and on both computers where I tested it I got "error writing or reading
protected memory". Similar code worked just fine in VBA.

At this time I'm not sure if I didn't fill in all the missing values
correctly in C# for the CheckSpelling() method or if there's really
something funky going on when the call is made from managed code. That's
something I have to look into, but I don't have time to do that for a few
days.

If you get to test it and you're using managed code then let us know how it
goes.

If you're using VB6 it should be OK, that's basically the same as VBA.
 
B

Brian McCullough

Ken/All,

This seems to work just fine for me and I am using VB.NET 1.1.

Here is my code:

If outlookVersion >= OUTLOOK_2007_VERSION Then
Dim objDoc As Word.Document
objDoc = inspector.WordEditor
objDoc.CheckSpelling()
Else
'do spell checking the old way (i.e. for Outlook 2003
and 2002)
End If

I guess there is no way to determine if the user hits the "Cancel" button
and cancels the spell check? I'd like to be able to determine this to know
if I should send the message or not. If the user cancels the spell check,
I'd like to prompt them to see if they want to send the message anyway, just
like Outlook does when you use the regular "Send" button.

Thanks!!

Brian
 
K

Ken Slovak - [MVP - Outlook]

As far as I know there's no way to get that from the dialog without doing
hacks using Win32 API calls and subclassing the dialog to intercept mouse
clicks and keyboard presses directed to the dialog. You'd have to see if
those are directed at the location of the Cancel button and if so take your
prompt action then.
 
B

Brian McCullough

Ken,

That is what I thought. Pretty much the same as the similar question I
asked about doing this for Outlook XP's Spell Check dialog.

Do you happen to know of any examples of doing something like this? Is it
even possible since the code that would get the handle of the dialog window
would have to live in my custom application, but my application doesn't
actually continue execution until after the CheckSpelling method is called?

For example assuming I am using the code I previously posted, I would have
to somehow setup my application to get the window handle somewhere before I
make the call to objDoc.CheckSpelling(), but how could I get the window
handle if the window hadnt yet been shown??


Thanks!!

-Brian
 
B

Brian McCullough

Ken,

What about checking the count of errors after performing the spell check?
If the count = 0, then assume that the spell check completed. If the count
0 then assume that the user canceled the spell check? Something like
this:

Dim objDoc As Word.Document
objDoc = inspector.WordEditor
objDoc.CheckSpelling()
If objDoc.SpellingErrors.Count > 0 Then
If MsgBox("There are still spelling errors, do you
wish to send the message anyway?", MsgBoxStyle.YesNo, "Custom Send Routine")
= MsgBoxResult.Yes Then
'send the message
End If
Else
'send the message
End If

Thoughts/comments on this approach?

-Brian
 
K

Ken Slovak - [MVP - Outlook]

I've never had to call for spelling check in any of the COM addins I've
written, so I have no idea. Try it and see if it works :)
 
K

Ken Slovak - [MVP - Outlook]

I know of lots of subclassing examples but none directed towards what you
want to do. Getting the hWnd of the window does seem to make this very
difficult or impossible since the spelling dialog call would seem to be
modal to your code.
 

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

Top