Outlook VBA script - vbYesNoCancel question

Tjcrouch2024 20 Reputation points
2024-10-18T21:14:49.59+00:00

I am attempting to update an existing VBA script I have that is almost working as intended.

Here is currently what I have been using:

Private Sub Application_ ItemSend (ByVal Item As Object, Cancel As Boolean)

On Error Resume Next

prompt$ = "Does this need to be sent secure?"

If MsgBox (prompts,

bYesNo + vbQuestion + vbMsgBoxSetForeground, "Does this need to be sent secure?") - bYes Then

strSubject = Item. Subject

• Prefix subject with [secure]

strSubject = "[Secure]" & strSubject

• Set the message subject

Item. Subject = strSubject

End if

End sub

Right now, when hitting the send button it creates a pop up to ask if it should be secure, if yes, it adds [Secure] to the email. If no, just sends it.

I would like to determine how to have a 3rd option for cancel, so that the email in its entirety can be stopped, but can’t seem to get that figured out quite right.

Outlook
Outlook
A family of Microsoft email and calendar products.
3,983 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 34,346 Reputation points
    2024-10-19T14:34:35.79+00:00

    Try this.

    Private Sub Application_ItemSend (ByVal Item As Object, Cancel As Boolean)
    	On Error Resume Next    
    	prompts = "Does this need to be sent secure?"
    	choice =  MsgBox (prompts, vbYesNoCancel + vbQuestion + vbMsgBoxSetForeground, "Does this need to be sent secure?")
    	if choice = vbYes then
    		strSubject = "[Secure]" & strSubject
    	elseif choice = vbNo then 
    		strSubject = strSubject
    	else 
    		exit sub        ' User hit cancel, we're done here.
    	End if
    
    	' Send the email here.
    
        if err.number <> 0 then 
    	    Msgbox "We creashed. " & err.description
         end if 
    End sub
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.