locked
Over riding Default controls in Word using Custom UI editor and VBA RRS feed

  • Question

  • Hi all.

    I would like to override the default file open button in QAT. I use the following code. But this is not working. Please help.

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"> <ribbon startFromScratch="true"> 
    
    
    
    <officeMenu>
    
    <button id="MyCustom1" imageMso="FileOpen" screentip="This is Happy" supertip="Click here for a happy message" onAction="office_FileOpen" visible="true"/> 
    
    </officeMenu>
    
    <qat>
    
    
    
    
    
    <sharedControls> 
    
    <control idMso="Bold" screentip="Make it Bold" supertip="Click here to make the selected text bold."/> 
    
    <button idMso="FileOpen" imageMso="FileOpen" screentip="This is Happy" supertip="Click here for a happy message" onAction="office_FileOpen"/> 
    
    </sharedControls> 
    
    
    
    
    
    </qat> 
    
    </ribbon>
    
     </customUI> 


    I have to overide the FileOpen control. But it is not going to onAction command. Please help.


    Hari :) ============================================================ "Yesterday is history, tomorrow is a mystery, and today is a gift, that's why they call it the present." ===========================================================
    • Edited by hari sukesh Tuesday, July 5, 2011 5:56 PM corrected the spelling
    Tuesday, July 5, 2011 5:56 PM

Answers

  • Hi Hari,
    Here is the sample code:

    [XML]
    <?xml version="1.0" encoding="utf-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
     <commands>
      <command idMso="FileOpen" onAction="office_FileOpen" />
     </commands>
     <ribbon startFromScratch="true">
      <qat>
       <sharedControls>
        <button idMso="FileOpen" screentip="This is Happy" supertip="Click here for a happy message" />
       </sharedControls>
      </qat>
     </ribbon>
    </customUI>
    



    [Module]
    Private Sub office_FileOpen(control As IRibbonControl, ByRef cancelDefault)
     If MsgBox("Do you really open file...?", vbYesNo) = vbYes Then cancelDefault = False
    End Sub
    


    Hope this helps,

    Regards,
    • Marked as answer by hari sukesh Thursday, July 7, 2011 4:47 AM
    Thursday, July 7, 2011 1:09 AM
  • Hi Hari,
    Here is the sample code:

    [XML]
    <?xml version="1.0" encoding="utf-8"?>
    <customUI onLoad="Ribbon_onLoad" xmlns="http://schemas.microsoft.com/office/2006/01/customui">
     <ribbon startFromScratch="true">
      <qat>
       <documentControls>
        <button idMso="FileOpen" />
        <button id="btnSample1" imageMso="A" />
        <button id="btnSample2" imageMso="B" />
        <button id="btnSample3" imageMso="C" />
       </documentControls>
      </qat>
     </ribbon>
    </customUI>
    

    [Module]
    Option Explicit
    
    Private Sub Ribbon_onLoad(ribbon As IRibbonUI)
     'Office 2007 Need Create New Document(and Close it).
     Application.Documents.Add.Close
    End Sub
    

    Hope this helps.

    kinuasa
    • Marked as answer by hari sukesh Thursday, July 7, 2011 4:47 PM
    Thursday, July 7, 2011 7:16 AM

All replies

  • How to add a custom Button in Quick Access tool Bar in word using Custom UI XML editor? I am able to add inbuilt controls such as Bold, cut etc. But I am not able to add a custom one in to QAT. I am able to create custom tabs and buttons inside it. But not in QAT.
    <qat>
    
     <sharedControls>
    
      <button id="button1" imageMso="HappyFace" />
    
     <button idMso="Cut" />
    
     </sharedControls>
    
    </qat>

    Here the "button1" is not showing up. Please help.
    • Edited by hari sukesh Tuesday, July 5, 2011 2:13 PM expanded QAT
    • Changed type hari sukesh Tuesday, July 5, 2011 2:24 PM
    • Merged by Cindy Meister MVP Thursday, July 7, 2011 8:08 AM Same discussion.
    Tuesday, July 5, 2011 12:28 PM
  • Hi Hari

    This is by design. In essence, the QAT belongs to the user. The only way you can affect the QAT is to set the startFromScratch attribute = "true" which means you'd need to define the entire ribbon (from scratch)


    Cindy Meister, VSTO/Word MVP
    Tuesday, July 5, 2011 3:30 PM
  • Hi Cindy,

    Thanks for your reply.

    I am also doing the same. I had set the startFromScratch attribute = "true" . Then also I am not getting the desired result. The custom button is not showing up. All other inbuilt buttons like 'Cut', 'paste' etc are coming up.

    Now I am thinking of adding some built in functionality in QAT and overide it using VBA. IS it possible? Please advise.


    Hari :) ============================================================ "Yesterday is history, tomorrow is a mystery, and today is a gift, that's why they call it the present." ===========================================================
    Tuesday, July 5, 2011 4:22 PM
  • hi all,

     

    any suggestions?

     

     


    Hari Sukesh
    Wednesday, July 6, 2011 6:24 AM
  • Hi Hari,
    Here is the sample code:

    [XML]
    <?xml version="1.0" encoding="utf-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
     <commands>
      <command idMso="FileOpen" onAction="office_FileOpen" />
     </commands>
     <ribbon startFromScratch="true">
      <qat>
       <sharedControls>
        <button idMso="FileOpen" screentip="This is Happy" supertip="Click here for a happy message" />
       </sharedControls>
      </qat>
     </ribbon>
    </customUI>
    



    [Module]
    Private Sub office_FileOpen(control As IRibbonControl, ByRef cancelDefault)
     If MsgBox("Do you really open file...?", vbYesNo) = vbYes Then cancelDefault = False
    End Sub
    


    Hope this helps,

    Regards,
    • Marked as answer by hari sukesh Thursday, July 7, 2011 4:47 AM
    Thursday, July 7, 2011 1:09 AM
  • Hi Hari,
    Here is the sample code:

    [XML]
    <?xml version="1.0" encoding="utf-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
     <commands>
     <command idMso="FileOpen" onAction="office_FileOpen" />
     </commands>
     <ribbon startFromScratch="true">
     <qat>
      <sharedControls>
      <button idMso="FileOpen" screentip="This is Happy" supertip="Click here for a happy message" />
      </sharedControls>
     </qat>
     </ribbon>
    </customUI>
    



    [Module]
    Private Sub office_FileOpen(control As IRibbonControl, ByRef cancelDefault)
     If MsgBox("Do you really open file...?", vbYesNo) = vbYes Then cancelDefault = False
    End Sub
    


    Hope this helps,

    Regards,
    Thanks for your help........

    Hari Sukesh
    Thursday, July 7, 2011 4:47 AM
  • Hi Hari,
    Here is the sample code:

    [XML]
    <?xml version="1.0" encoding="utf-8"?>
    <customUI onLoad="Ribbon_onLoad" xmlns="http://schemas.microsoft.com/office/2006/01/customui">
     <ribbon startFromScratch="true">
      <qat>
       <documentControls>
        <button idMso="FileOpen" />
        <button id="btnSample1" imageMso="A" />
        <button id="btnSample2" imageMso="B" />
        <button id="btnSample3" imageMso="C" />
       </documentControls>
      </qat>
     </ribbon>
    </customUI>
    

    [Module]
    Option Explicit
    
    Private Sub Ribbon_onLoad(ribbon As IRibbonUI)
     'Office 2007 Need Create New Document(and Close it).
     Application.Documents.Add.Close
    End Sub
    

    Hope this helps.

    kinuasa
    • Marked as answer by hari sukesh Thursday, July 7, 2011 4:47 PM
    Thursday, July 7, 2011 7:16 AM