none
Save AS code in VSTO can't valid in Excel and PPT 2013, but can valid in Word 2013 RRS feed

  • Question

  • by follow bellow code , I build a Word 2013 VTSO 

    <?xml version="1.0" encoding="UTF-8"?>

    <customUI xmlns="

    http://schemas.microsoft.com/office/2009/07/customui 

     

    " onLoad="Ribbon_Load">

      <commands>    

        <command idMso="TabSave"   Enabled="false"/>

        <command idMso="TabShare"  Enabled="false"/>

        <command idMso="TabPrint"  Enabled="false"/>

      </commands>

    </customUI>

    It can run and disable the SAVE AS function in word 2013

    While  I build a Excel/PPT  2013 VTSO by follow the code as well, It can't working?

    My question is that , is this code wrong for Excel/PPT  2013 VTSO? how to write a right code? many thanks 


    I sale myself ONLY half CNY!

    Tuesday, November 7, 2017 8:57 AM

All replies

  • by follow bellow code , I build a Word 2013 VTSO 

    <?xml version="1.0" encoding="UTF-8"?>

    <customUI xmlns="

    http://schemas.microsoft.com/office/2009/07/customui 

     

    " onLoad="Ribbon_Load">

      <commands>    

        <command idMso="TabSave"   Enabled="false"/>

        <command idMso="TabShare"  Enabled="false"/>

        <command idMso="TabPrint"  Enabled="false"/>

      </commands>

    </customUI>

    It can run and disable the SAVE AS function in word 2013

    While  I build a Excel/PPT  2013 VTSO by follow the code as well, It can't working?

    My question is that , is this code wrong for Excel/PPT  2013 VTSO? how to write a right code? many thanks 


    I sale myself ONLY half CNY!

    Wednesday, November 8, 2017 1:09 AM
  • Hi,

    This is the forum to discuss questions and feedback for Microsoft Excel features, I'll move your question to the MSDN forum for Excel

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.


    Regards,
    Emi Zhang
    TechNet Community Support

    Please remember to mark the replies as answers if they helped.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, November 8, 2017 2:11 AM
  • Hello,

    The code works fine for me in 15.0.4971.1002.

    Please uncheck all other add-ins when testing to avoid conflicts.

    When you use the same xml in Excel and PowerPoint add-in, do you paste the code from Ribbon.cs into ThisAddIn.cs?

            protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
            {
                return new Ribbon1();
            }

    If you confirm the ribbon is loaded, please go to Excel Options-> Advanced -> General to check "Show add-in user interface errors". Then run your add-in again to see if there is any UI error.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 8, 2017 2:33 AM
    Moderator
  • sorry,I can not find Excel Options-> Advanced -> General to check "Show add-in user interface errors"

    Can you share your example with me?thank you


    忘忧草,我的博客http://xiangzhangjun2006.blog.163.com

    Wednesday, November 8, 2017 3:25 AM
  • Hello,

    Please go to File -> Options -> Advanced -> General -> Show add-in user interface errors

    If the issue still exists, please create a new add-in using the following xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <commands>
        <command idMso="TabSave" enabled="false"/>
        <command idMso="TabShare" enabled="false"/>
        <command idMso="TabPrint" enabled="false"/>
      </commands>
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">
            <group id="MyGroup"
                   label="My Group">
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 8, 2017 6:44 AM
    Moderator
  • It's great!

    it can working to disable the save as tab. many thanks again.


    I sale myself ONLY half CNY!

    Wednesday, November 8, 2017 8:04 AM
  • thanks.

    disable excel and ppt is ok.

    Please open the path according to how to get the document in the PPT.

    I determine if the other is disabled by the acquisition path.

    xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <commands>
        <command idMso="TabSave" getEnabled="GetSavePPTEnabled"/>
        <command idMso="TabShare" getEnabled="GetSavePPTEnabled"/>
        <command idMso="TabPrint" getEnabled="GetSavePPTEnabled"/>
      </commands>
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">
            <group id="MyGroup"
                   label="My Group">
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    cs:

      public bool GetSavePPTEnabled(Office.IRibbonControl control)
            {


                try
                {
                    string strDefaultLoc = "http://rmssps";

                    string paths = Globals.ThisAddIn.Application.ActiveProtectedViewWindow.SourcePath;
                    if (paths.Contains(strDefaultLoc))
                        return false;
                    else
                        return true;

                }
                catch (Exception ex)
                {
                    return true;
                }

            }

    Is that correct?

    thanks


    忘忧草,我的博客http://xiangzhangjun2006.blog.163.com

    Wednesday, November 8, 2017 9:15 AM
  • It's great!

    it can working to disable the save as tab. many thanks again.


    I sale myself ONLY half CNY!

    Hello,

    I notice you have posted several thread for a same issue. You may delete these thread. The answered state of this thread is lost after merging or splitting. Please mark helpful posts as answer to close this thread again.

    Sorry for any inconvenience.

    If you have any other new issues when developing with Office Object Model, please feel free to post on our forum.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 8, 2017 9:16 AM
    Moderator
  • Hi,

    I want to determine whether or not another is disabled by the path.

    xml:

     <commands>
        <command idMso="TabSave"   getEnabled="GetSaveEnabled"/>
        <command idMso="TabShare"  getEnabled="GetSaveEnabled"/>
        <command idMso="TabPrint"  getEnabled="GetSaveEnabled"/>
      </commands>

    result:

    If it is a server-side path, disable it, and if it's local, not disable .I've already done that

    code:

    public bool GetSaveEnabled(Office.IRibbonControl control)
            {
                //返回值
                bool disabled = true;
                //
                try
                {
                    //SP服务器的URL
                    string strDefaultLoc = "https://avanade-my.sharepoint.com";//"http://szx1000380271";
                    
                    Microsoft.Office.Interop.Word.Application app = Globals.ThisAddIn.Application;
                    //如果为空
                    if (app == null)
                    {
                        disabled = true;
                    }
                    else
                    {
                        //得到路径
                        string paths = app.ActiveDocument ==null?string.Empty:app.ActiveDocument.Path;
                        
                        //缓存
                        if (paths.Contains(strDefaultLoc))
                        {
                            //保存成缓存
                            CacheHelper.SetCache("RMSwordSaveAS", false,14400);
                            //返回false
                            disabled = false;
                        }
                        else
                        {
                            //先判断缓存是否有值
                            bool isDisable = CacheHelper.GetCache("RMSwordSaveAS") == null ? true : bool.Parse(CacheHelper.GetCache("RMSwordSaveAS").ToString());
                            //复制给
                            disabled = isDisable;
                        }
                    }


                }
                catch (Exception ex)
                {
                    disabled= true;
                }
                //返回值
                return disabled;

            }

    question:

    1、Using the cache, you can open the service file first.You can disable another save when you open local

    2、Using the cache, you can open the local file first.You can not disable another save by opening the server file

    How to solve it?thanks



    忘忧草,我的博客http://xiangzhangjun2006.blog.163.com

    Thursday, November 9, 2017 6:46 AM
  • Hello,

    As the original issue has been resolved, I suggest create a new thread. We could focus on your new issue in the new thread. Thanks for your understanding.

    Besides, in the new thread, you may share us what is the cache and how do yo want to use it. In my opinion, to determine whether disable the commands, you could check the path and then disable or enable if it is a network path or local path. 

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by LOVE007 Wednesday, November 15, 2017 11:10 AM
    Thursday, November 9, 2017 6:56 AM
    Moderator
  • https://social.technet.microsoft.com/Forums/office/en-US/5e2d8916-7478-4c92-92ab-7b06d197328c/word2013ppt2013excel2013i-want-to-disable-the-saveas-button-according-to-the-path?forum=officesetupdeploy

    thanks


    忘忧草,我的博客http://xiangzhangjun2006.blog.163.com

    Wednesday, November 15, 2017 11:10 AM
  • Hello,

    Please post a new thread for a new issue. If you have any development issue, please post on  https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=officedev

    If you have any issue about Office Products or features, please post on 

    https://social.technet.microsoft.com/Forums/office/en-US/home?category=officeitpro

    We do not support TechNet forums. For this thread you post on TechNet, we would take action ASAP after the thread moves to our forum.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 16, 2017 2:31 AM
    Moderator