none
CancelDefault not working when repurposing the FileSendAsAttachment command RRS feed

  • Question

  • Hi,

    I'm trying to repurpose the Send As Attachment command in Word 2010 within a global template. Everything is working and my custom routine is being called, but I cannot stop Word also running the default "FileSendAsAttachment" command, so I end up with 2 emails generated with the document attached. I have set the CancelDefault parameter to True, which works for the "FileEmailAsPdfEmailAttachment" command, but no matter what I do I cannot prevent the default "FileSendAsAttachment" command from running.

    Has anyone else experienced this, or have a working example of what I should do to get it working? Since it's working for the PDF Attachment command, I suspect it's an issue with Word.

    In the CustomUI XML for the template, I have the following:

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" xmlns:PA="PiperAlderman" onLoad="PA_OnLoad">
    	<commands>
    		<command idMso="FileSendAsAttachment" onAction="Command_OnAction"/>
    		<command idMso="FileEmailAsPdfEmailAttachment" onAction="Command_OnAction"/>
    	</commands>
    </customUI >
    
    Within the template, I have the following VBA code:

    Public Sub Command_OnAction(control As IRibbonControl, ByRef CancelDefault)
        Select Case control.ID
        
            Case "FileSendAsAttachment"
                SendDocumentAsAttachment
                CancelDefault = True
                
            Case "FileEmailAsPdfEmailAttachment"
                SendDocumentAsPDFAttachment
                CancelDefault = True
        
        End Select
    End Sub
    
    Any help greatly appreciated. Thanks.
    Tuesday, April 3, 2012 1:10 PM

Answers

  • Hi Bruce,

    Thanks for your response.

    I'm running 2010 32 bit also, but since it's working for you I tried looking at something else and found that the command is also repurposed by another add-in (Autonomy WorkSite)

    I've now customised WorkSite so it doesn't intercept the command, and now my code works perfectly. Obviously having two customisations trying to do the same thing will cause issues.

    Thanks again for your help.

    Regards

    Chris

    • Marked as answer by Sir HC Wednesday, April 4, 2012 4:34 AM
    Wednesday, April 4, 2012 4:34 AM

All replies

  • Hi Sir HC,

    I can't reproduce the problem on my side. What is the version of your Word applicaiton? Mine is 2010 32bit.

    I use the following ribbon xml and code snippet:

    Ribbon Xml:

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    	<commands>
    		<command idMso="FileSendAsAttachment" onAction="Command_OnAction"/>
    		<command idMso="FileEmailAsPdfEmailAttachment" onAction="Command_OnAction"/>
    	</commands>
    </customUI>

    VBA code: 

    Public Sub Command_OnAction(control As IRibbonControl, ByRef CancelDefault)

    CancelDefault = True
       ' MsgBox control.ID
        Select Case control.ID
        
    '        Case "FileSendAsAttachment"
    '            SendDocumentAsAttachment
    '            CancelDefault = True
    '
    '        Case "FileEmailAsPdfEmailAttachment"
    '            SendDocumentAsPDFAttachment
    '            CancelDefault = True
        
        End Select
    End Sub


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, April 4, 2012 2:27 AM
  • Hi Bruce,

    Thanks for your response.

    I'm running 2010 32 bit also, but since it's working for you I tried looking at something else and found that the command is also repurposed by another add-in (Autonomy WorkSite)

    I've now customised WorkSite so it doesn't intercept the command, and now my code works perfectly. Obviously having two customisations trying to do the same thing will cause issues.

    Thanks again for your help.

    Regards

    Chris

    • Marked as answer by Sir HC Wednesday, April 4, 2012 4:34 AM
    Wednesday, April 4, 2012 4:34 AM
  • Looks you have already found the solution Chris... lol
    Wednesday, April 4, 2012 6:07 AM