Hi
I have question regarding Outlook VBA, i created a macro in Excel which looked at a OUtlook email and checked everything including the address, subject and attachments, and it also peformed a spell check on the body content by copying and pasting it into excel and then spellchecking it.
However i want to move this macro to however so far i have managed to do everything except peform a spell check on the body content. So far i ahve the code below, which when started will check for a to email address and cancel if there isn't one, then if there is a to address, it will do the same for the subject. It will then check the body content for the word attach and if there is but no attachments it will check this with the user. However when it gets to the line marked in red in the spell check part it fails.
Code:
Sub EmailCheck()
Dim objmail As Object
Dim ReceieverCheck As String
Dim SubjectCheck As String
Dim SpellCheck As String
Dim SpellCheck1 As String
Dim AttachCheck As String
Dim AttachCount As Integer
Dim strThismsg As String
Set objmail = ActiveInspector.CurrentItem
If objmail.To = "" Then
MsgBox "There is no address in the To box. Please add one and re-run check", vbOKOnly, "No Subject"
Exit Sub
Else
ReceieverCheck = MsgBox("This Message is being sent to: '" & objmail.To & objmail.CC & "' '" & "' Is this correct", vbYesNo, "Reciever Check")
If ReceieverCheck = vbNo Then
Exit Sub
End If
End If
If objmail.Subject = "" Then
MsgBox "There is no subject in Subject box. Please add one and re-run check", vbOKOnly, "No Subject"
Exit Sub
Else
SubjectCheck = MsgBox("This Message has a subject of: '" & objmail.Subject & "' Is this correct", vbYesNo, "Subject Check")
If SubjectCheck = vbNo Then
Exit Sub
End If
End If
AttachCount = objmail.Attachments.Count
strThismsg = objmail.Body
If InStr(LCase(strThismsg), "attach") > 0 Then
If AttachCount = 0 Then
AttachCheck = MsgBox("Your email mentions attachments however there are no documents attached. Is this correct?", vbYesNo, "Attachment Check")
If AttachCheck = vbNo Then
Exit Sub
End If
Else
AttachCheck = MsgBox("There are " & AttachCount & " attachments on this email. Is this correct?", vbYesNo, "Attachment Check")
If AttachCheck = vbNo Then
Exit Sub
End If
End If
End If
SpellCheck = MsgBox("Has this message been spell checked?", vbYesNo, "Spelling Check")
If SpellCheck = vbNo Then
SpellCheck1 = MsgBox("Select Yes to perform a spell check or No to continue", vbYesNo, "Spellcheck")
If SpellCheck1 = vbYes Then
objmail.Body.select
Selection.SpellCheck
End If
End If
MsgBox "Email Check Complete. Select ok and Send the message", vbOKOnly, "Check Complete"
End Sub
What i want is for it to ask the user if the body has been spell checked and if not to ask the user to select yes to spellcheck or no to continue. When the user selects yes i wanted it to spellcheck the body of the email.
The spellcheck code i used worked in excel when i selected the cell and did selection.spellcheck.
Can anyone tell me what is wrong with the code?
Thanks,
Jeskit