SetFocus for built-in Outlook mail form with VBA
Posted on 2003-03-05
As part of a Send and File mail message routine I've implemented using a custom toolbar button in Outlook XP, I attempt to invoke the ActiveInspector.CommandBars("Tools").Controls("Spelling...").Execute method before performing an ActiveInspector.CurrentItem.Send method. Unfortunately, the Tools/Spelling menu item is inactive (and thus fails when called by VBA code) if the focus of the built-in Outlook mail form is not on the Subject or Body form controls (i.e. if it's instead in the From, To, CC fields). So, prior to invoking the "Spelling..." menu item, I first need to set the focus of the form to the Subject or Body form control.
This sounds simple enough, but it is not. Let me tell you a few things that DO NOT work:
1) ActiveInspector.CurrentItem.Body.SetFocus - this does NOT work because the MailItem.Body property is NOT the same as the body form control, and SetFocus will not work
2) ActiveInspector.ModifiedFormPages("Message").Controls("Message").SetFocus - this does NOT work because the ModifiedFormPages collection is empty when you are using the default/built-in Outlook forms. This option would work if I was using custom forms, but I am not.
3) Prompting the user to place the cursor in the Subject/Body fields if it's not there - this will NOT work as a solution because the customer wants a TRUE solution (nice try though)
So, here's the question, for which an answer would be enormously appreciated
1) How can I set the focus of the default/built-in (NOT custom) Outlook mail message form to the Subject or Body fields using Outlook VBA from the VbaProject.OTM project?
P.S. The reason I'm attempting to use the menus to invoke the spell checker is that I could not figure out a way to invoke it any other way. There does not appear (in the research I've done at least) to be a way perform the .CheckSpelling method in Outlook like you can in Word or Excel. If you can tell me how to invoke the spell checker without the menu, which bypasses the SetFocus problem I face, you get the points, a blue ribbon, and a free pizza.