How to save message before the spelling start ?

B

Bragu

We have a problem: if we have setted the option to spell the mail before
sending the outlook, sometimes, crash and we lose the mail.

I want to write a macro that save the mail before sending, so if the
application crash we don't lose the mail.
But the event send of MailItem is rised after the spelling it's runned.
Is there any way to save it before the spelling start ?

I wrote a macro (copy from explamples on internet) that work we commandbars
button (see Sub SaveSpellSend attached ) but it's not a nice way because if
somebody stop the spell checking the mail will be sended anyway.

Thank's for any help ... and sorry for my english

ps: Our system are w2k/ xp with office 2000 SR1 multilanguage pack with all
the last fix installed.




Sub SaveSpellSend()
Dim objApp As Outlook.Application
Dim objInspector As Outlook.Inspector
Dim objItem As MailItem
Dim strRecipName As String
Dim flgErr As Integer

flgErr = 0
On Error GoTo errHandler
Set objApp = CreateObject("Outlook.Application")
Set objInspector = objApp.ActiveInspector
If Not TypeName(objInspector) = "Nothing" Then
Set objItem = objInspector.CurrentItem
If objItem.Class = olMail And _
objItem.Sent = False Then
objItem.Save
flgErr = 1
If CheckSpelling Then
objItem.Send
Else
MsgBox "Per poter eseguire il controllo ortografico il cursore
deve trovarsi nel body", vbExclamation
End If
End If
End If
Set objItem = Nothing
Set objInspector = Nothing
Set objApp = Nothing
Exit Sub
errHandler:
Select Case flgErr
Case 1:
MsgBox "Il messaggio è stato salvato ma non è stato possibile
eseguire il controllo ortografico", vbInformation, "Check Mail"
Case 287:
MsgBox "Mail non spedito come da vostra scelta.", vbInformation,
"Check Mail"
Case Else
MsgBox "Errore : " & "(" & Err.Number & ")" & vbCrLf &
Err.Description, vbCritical, "Errore nel controllo/invio mail"
End Select

End Sub
 
E

Eric Legault [MVP - Outlook]

Outlook provides no hooks into the spell checking event.

If you want to ensure that messages are saved before sending, one way to do
this without code is to turn on the AutoSave option in Advanced E-mail
Options.

BTW, the Send event is firing after the spell check is run because the user
has clicked Send, which runs spell check first if it is turned on.

If you must use code, simply trap the Send event for all new e-mails and
call the Item.Save event. See this article on how to hook into this:

Getting a Handle on Your E-mails with VBA:
http://blogs.officezealot.com/legault/articles/2224.aspx

If Outlook is crashing with no code running because of the spell check, you
might want to try running Detect and Repair in Office Setup.
 
B

Bragu

Hi Eric,

I had already tryed what you suggest: trap the send event, but this event
is rised after the spellchecking has runned so for me it's to late --> maybe
the outlook as already crashed.

As you say I could repaire my office installation but the problem exist on >
100 PC of my Company so if I found a workround will be better.

Do you know if there is a way to Know the answer a the spellcheker question:
"The spelling check was stopped before it finished. Do you want to send
anyay?" when you stop the spell check?
If I can trap this I resolve my problem using the code I posted and modifing
the function:

Function CheckSpelling()
' SpellChecker ID = 2

Dim ctrl As CommandBarControl
' Set cbrMenuBar = Application.ActiveInspector.CommandBars '("Standard")
' cbrMenuBar.FindControl(, 2).Execute
Set ctrl = Application.ActiveInspector.CommandBars.FindControl(, 2)
If ctrl.Enabled Then
ctrl.Execute '==== How trap the spelling cancel button ?
End If
End Function
 
B

Bragu

Hi,

I tried also this way (see code) but I get the Automation Error.
What I can do to skip this error ? I have already certificate my macro and
setted the certificate as trusted.


Sub mySend()
Dim objApp As Outlook.Application
Dim objInspector As Outlook.Inspector
Dim objItem As MailItem
Dim strRecipName As String
Dim flgErr As Integer
Dim ctrl As CommandBarControl

flgErr = 0
On Error GoTo errHandler
Set objApp = CreateObject("Outlook.Application")
Set objInspector = objApp.ActiveInspector
If Not TypeName(objInspector) = "Nothing" Then
Set objItem = objInspector.CurrentItem
If objItem.Class = olMail And _
objItem.Sent = False Then
objItem.Save
'send ==== the next line return an automation Error !!!!
Set ctrl = Application.ActiveInspector.CommandBars.FindControl(,
2617)
ctrl.Execute
End If
End If
Set objItem = Nothing
Set objInspector = Nothing
Set objApp = Nothing
Exit Sub
errHandler:
Select Case flgErr
Case 1:
MsgBox "Il messaggio è stato salvato ma non è stato possibile
eseguire il controllo ortografico", vbInformation, "Check Mail"
Case 287:
MsgBox "Mail non spedito come da vostra scelta.", vbInformation,
"Check Mail"
Case Else
MsgBox "Errore : " & "(" & Err.Number & ")" & vbCrLf &
Err.Description, vbCritical, "Errore nel controllo/invio mail"
End Select

End Sub
 
E

Eric Legault [MVP - Outlook]

As I said, you cannot automate spell checking in any way, other than trapping
when the user clicks the Spelling menu item or command bar button, and there
is where you can cancel the spell check. However, you cannot interact with
any of the spell check dialogs with the Outlook Object model. You can try
using the VBA SendKeys function to mimic clicking some of the buttons on that
dialog, but SendKeys is always hit and miss.

The bigger issue is why your Outlook installations are crashing during spell
check. Some points:

- upgrade to Office 2000 SP 3
- are you using custom dictionaries?
- does this apply:
http://support.microsoft.com/default.aspx?scid=kb;en-us;241485
- consider opening an incident with MS Product Support

Once your spell check issues are resolved, then you can reliably save the
message with code before sending.
 
E

Eric Legault [MVP - Outlook]

1) You don't need to define a variable set to the Outlook.Application object
in VBA code; you can use the intrinsic Application object without a new
variable required, and you don't need to instantiate it.

2) This will fail if the current Inspector is not a MailItem, as objItem is
declared as a MailItem object:

Set objItem = objInspector.CurrentItem
If objItem.Class = olMail And _...

Check objInspector.CurrentItem.Class before setting your objItem variable.

3) I don't know what is happening with your ctrl object. Where are you
calling that procedure? During the Item_Send event?
 
B

Bragu

Hi Eric,

thank's for the answer and to show me some error on my code.

My Idea was to add to the tools bar a button executing mySend Macro .
This button will be used instead of the standard Send button.
The Ctrl is pointing to the commandBars button &send, so triing to executing
it ,after have saved the mail, will send the mail (and executing the spell
chek).
But when I exec tha ctrl I get : Automation Error
I think this is a security protection error

Anyway I will do what your suggest: opening incident with MS Product
Support, because the problem is prensent also on PC with o2k sp3
multilanguage pack (vocabulary Italian).


Thank's again
 
E

Eric Legault [MVP - Outlook]

I often see those "automation" errors when trying to access the CommandBars
collection from an Explorer or Inspector object when either of those aren't
available - usually when Outlook or an item window is opening or closing. In
your case though, it appears that you are calling the commandbar button
before you initiate the Send method, so I'm at a loss to explain why you are
experiencing this issue.
 

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