Consulting

Results 1 to 9 of 9

Thread: When more than "ItemSend" is needed

  1. #1

    When more than "ItemSend" is needed

    Hi could someone help?

    I have a Add-in in Outlook (Newforma) that uses the Application_ItemSend function. You can send an email by clicking on Outlooks Send button or on this Addins button.

    I wanted to write a small msgbox to remind people to use the Addin when they click on Outlook's Send button.

    However because both these buttons trigger the Application_ItemSend my macro runs regardless which button I click.

    I need a way to only trigger my code when the Send button is pressed by the user not when the Application_ItemSend function is sent please?

    I am a beginner to VBA so if answers could be in full that would be most helpful.

    Thank you in advance, here's the code I have done so far:

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    If MsgBox("Make sure you are sending using Newforma - Are you sure you want to send this message?", vbYesNo + vbQuestion + vbMsgBoxSetForeground, "WARNING - NEWFORMA BYPASS ?") = vbNo Then

    Cancel = True

    End If


    End Sub

  2. #2
    Hi-

    I would write my code like this:

    If MsgBox("Make sure you are sending using Newforma - Are you sure you want to send this message?", vbYesNo) = vbNo Then
        Cancel = True
    End If
    Hope this helps,
    TheSilkCode

  3. #3

    Not really what I was asking

    Hi thanks for this but it's not exactly what I was asking?

    Quote Originally Posted by TheSilkCode View Post
    Hi-

    I would write my code like this:

    If MsgBox("Make sure you are sending using Newforma - Are you sure you want to send this message?", vbYesNo) = vbNo Then
        Cancel = True
    End If
    Hope this helps,
    TheSilkCode

  4. #4
    Well then what are you asking? I thought you said "I wanted to write a small msgbox to remind people to use the Addin when they click on Outlook's Send button." and that's what that does- if user doesn't select ok then cancel is passed during send message and it shouldn't be sent... please explain what part is missing.

    TheSilkCode

  5. #5

    ItemSend

    Quote Originally Posted by [COLOR=#141414
    However because both these buttons trigger the Application_ItemSend my macro runs regardless which button I click. [/COLOR]

    I need a way to only trigger my code when the Send button is pressed by the user not when the Application_ItemSend function is sent please?

    Sorry for the confusion?

    What I was asking was the above.

  6. #6
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Try using the Cancel parameter to differentiate Newforma from the Send button.

    Private Sub Newforma()
    ' Cancel = True is a flag indicating Newforma invoked Application_ItemSend
    Application_ItemSend CreateItem(0), True
    End Sub
    
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    
    If Cancel = False Then ' User clicked the Send button
        If MsgBox("Make sure you are sending using Newforma - Are you sure you want to send this message?", vbYesNo + vbQuestion + vbMsgBoxSetForeground, "WARNING - NEWFORMA BYPASS ?") = vbNo Then
            
            Cancel = True
            
        End If
    
    Else
        ' Cancel starts as True when Application_ItemSend was invoked by Newforma
        ' Reverse the Cancel
        Cancel = False
    
    End If
    
    End Sub
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  7. #7

    Not working sorry?

    Hi

    This hasn't helped I'm afraid? I think again because they both invoke Itemsend both the Newforma button and the standard send button are starting as true and therefore both triggering the Msgbox.

    I'm impressed by the concept. Would clicking the Cancel create a event that could be captured?

  8. #8
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    The Application_ItemSend event is described here.

    https://msdn.microsoft.com/en-us/lib...ffice.15).aspx

    There should be enough detail to see clicking on the Send button cannot set Cancel to True. Mail would never leave Outlook.
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  9. #9
    Hi

    I have changed the way I wish to do this (as the first way is not working).

    I have created a userform with 3 buttons on it - I have never linked my own form to VBA so here goes nothing ...

    Attachment 18211 this is the form

    -------------------------------------

    In the form I have:
    ---------------------------------------

    Option Explicit


    Private Sub CmdNoSendAnyway_Click()
    Me.Tag = 3
    Me.Hide
    End Sub


    Private Sub CmdOopsCancel_Click()
    Me.Tag = 2
    Me.Hide
    End Sub


    Private Sub CmdYesSend_Click()
    Me.Tag = 1
    Me.Hide
    End Sub


    Private Sub Userform_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then Cancel = True
    End Sub

    ------------------------------------

    On 'ThisOutlookSession' I have:

    -----------------------------------------


    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    Dim myForm As frmNFMsgBox
    Set myForm = New frmNFMsgBox
    myForm.Show vbModal


    Select Case myForm.Tag
    Case 1
    GoTo lbl_Exit
    Case 2
    Cancel = True
    Case 3
    GoTo lbl_Exit
    End Select


    lbl_Exit:
    Unload myForm
    Set myForm = Nothing
    Exit Sub
    End Sub

    Is this the best way to do this?

    Also the CloseMode private sub is not working? As in if I click the close X nothing happens? I would quite like not to have one really.

    any help greatly appreciated,

    TT.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •