none
Disable PRINT button in word 2010 RRS feed

  • Question

  • Hi,

    We have one VB application which customizes word document and removed all the menu items and tool bars. This works well with all the versions of ms-office except 2010. In word 2010, Print button under file menu is getting saved. 

    I tried the below code to make it disable

    objWord.CommandBars.ActiveMenuBar.Controls.Item(1).Controls.Item(16).Enabled = False

    But, still the Print button is getting enabled.

    Can anyone suggest me any ideas?

    Thanks in Advance.

    • Moved by Max Meng Sunday, April 17, 2011 6:16 AM (From:Word IT Pro Discussions)
    Thursday, April 14, 2011 11:16 AM

Answers

  • Hi,

     

    According to your description, it seems that you want to remove the print button from the File tab. File tab is backstage rather than ribbon like “Home”, “Insert”. So you are not able to control them easily like ribbon. However you can use XML code to do some customization.

     

    Please check the following document for some reference:

    Customizing the Office 2010 Backstage View for Developers

    Introduction to the Office 2010 Backstage View for Developers

     

    I hope this helps, and if you have any further concern, please let me know.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 19, 2011 11:22 AM
    Moderator
  • Hello.

    If you just want to disable/remove the Print button you can do that by modifying the Backstage.

    You can add this XML code to the document and it will hide the Print button, then you can add your own print button if you like to:

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
     <backstage>
       <tab idMso="TabPrint" visible="false"/>
     </backstage>
    </customUI>

    If you have not been modifying the Ribbon toolbar or the Backstage before, you can find the "Custom UI Editor For Microsoft Office" and download and install it.

    I hope I understood your question correct and my reply helped you.

    Regards
    Lars-Eric

    Tuesday, April 19, 2011 2:02 PM
  • Hello,

     

    There is another way to accomplish you goal. You can use the print event and Cancel it like so:

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
          Globals.ThisAddIn.Application.DocumentBeforePrint += 
    new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforePrintEventHandler(Application_DocumentBeforePrint);
          
        }
    
        void Application_DocumentBeforePrint(Microsoft.Office.Interop.Word.Document Doc, ref bool Cancel)
        {
          MessageBox.Show("Print is disabled");
          Cancel=true;
        }
    
    This code is in C#, but can be easily adapted for VB. I know, this is not elegant as the above, but it still does the trick.

     

    Hope this is helpfull,

    Silviu.


    http://www.rosoftlab.net/
    Thursday, April 21, 2011 5:35 AM

All replies

  • Hi,

     

    According to your description, it seems that you want to remove the print button from the File tab. File tab is backstage rather than ribbon like “Home”, “Insert”. So you are not able to control them easily like ribbon. However you can use XML code to do some customization.

     

    Please check the following document for some reference:

    Customizing the Office 2010 Backstage View for Developers

    Introduction to the Office 2010 Backstage View for Developers

     

    I hope this helps, and if you have any further concern, please let me know.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 19, 2011 11:22 AM
    Moderator
  • Hello.

    If you just want to disable/remove the Print button you can do that by modifying the Backstage.

    You can add this XML code to the document and it will hide the Print button, then you can add your own print button if you like to:

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
     <backstage>
       <tab idMso="TabPrint" visible="false"/>
     </backstage>
    </customUI>

    If you have not been modifying the Ribbon toolbar or the Backstage before, you can find the "Custom UI Editor For Microsoft Office" and download and install it.

    I hope I understood your question correct and my reply helped you.

    Regards
    Lars-Eric

    Tuesday, April 19, 2011 2:02 PM
  • Thx Calvin and larsg. Iam new to this. Can you please guide me whether i can achieve this only by writing lines of code in VB.
    Krishna Prakash
    Tuesday, April 19, 2011 5:04 PM
  • Can you please provide some VB code to use this custom XML
    Krishna Prakash
    Wednesday, April 20, 2011 6:12 PM
  • Hello Krishna,

    I don't know if you are using an Add-In or just using Word's Automation Interface to control Word. If you take look at the links Calvin gave in a previous reply I think they show you how to add the XML code when you are creating an Add-In. If you are just using Word's Automation Interface from another application, I'm not sure if you can add your own XML to a document.

    Sorry I can not help you anymore on this subject,

    Regards,
    Lars-Eric

    Wednesday, April 20, 2011 6:20 PM
  • I have a VB project from which we customize it before showing it to user.. We are disabling alll the menu bars and tool bars through vb code...Code works perfectly for all the versions of MS-Office.. But Print button is getting displayed when we use word 2010.

    My requirement is to use VB code to disable Print menu in word 2010


    Krishna Prakash
    Wednesday, April 20, 2011 6:24 PM
  • Hello Krishna,

    I don't think there is any way to programmatically thange the Backstage. Several things has changed with the introduction of the Backstage in Office 2010. We are banging our heads at the company I'm working for to make 'old' solutions to work in Office 2010, but difficult. If you for instance want to control printing and when creating new documents you can add code  like Sub FilePrint(), Sub FileNew() in VBA (in a global template or in a document) to change the functionality. You may want to validate a document before it's allow it to be printed, special printing and so on.  Those callback methods are no longer called after the introduction of the Backstage. You have to modify the Backstage

    This is somewhat a real pain. For big organisations like healthcare administrations with a greate number of documents and a lot of functionality tied to the documents it may be a pain to upgrade to Office 2010. To upgrade 5000-10000 computers can take several month, a year or more in worst case, and as it seems now the document base has to be doubled during the upgrade, one set of documents for Office 2007 and earlies and another set for Office 2010. That can make a huge additional cost to an upgrade to Office 2010, if you have to create and maintain two version of your documents.  

    I like the backstage even though it still has some flaws, but I also miss the backward compartibility we loose because of the Backstage.

    Regards,
    Lars-Eric

    • Proposed as answer by Istvan Bartos Monday, June 27, 2011 9:17 PM
    Wednesday, April 20, 2011 7:17 PM
  • Hello,

     

    There is another way to accomplish you goal. You can use the print event and Cancel it like so:

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
          Globals.ThisAddIn.Application.DocumentBeforePrint += 
    new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforePrintEventHandler(Application_DocumentBeforePrint);
          
        }
    
        void Application_DocumentBeforePrint(Microsoft.Office.Interop.Word.Document Doc, ref bool Cancel)
        {
          MessageBox.Show("Print is disabled");
          Cancel=true;
        }
    
    This code is in C#, but can be easily adapted for VB. I know, this is not elegant as the above, but it still does the trick.

     

    Hope this is helpfull,

    Silviu.


    http://www.rosoftlab.net/
    Thursday, April 21, 2011 5:35 AM
  • Hi Krishna.133

    Try the following:

    Sub FilePrint()
    Application.Dialogs(wdDialogFilePrint).Execute
    End Sub

    Worked for me.....


    Thanks for everything, all your help is well appreciated
    Friday, April 22, 2011 6:58 AM
  • Hello 'scorpdevil'

    Are you really using Word 2010?

    With the introduction of the 'Backstage' neither FileNew not FilePrint gets called in our documents. We have a lot documents developed for customers that relies on FilePrint (VBA in each document) for special printing. It can be validation of the document before it's printed, different pages to different printers or bins, not print instruction pages, hiding instruction text in the document when printing and so on. This is really a problem for us and organisations with several thousands of computers where it can take a year to upgrade all computers, so you can not have one version of the documents for all Office versions anymore. At least not untill all computers have Office 2010+.

    Regards,
    Lars-Eric

    Friday, April 22, 2011 9:26 AM
  • Larsg_sweden

    maybe this will help

    http://msgroups.net/microsoft.public.excel.programming/Disable-Print-button-pulldown-menu


    Thanks for everything, all your help is well appreciated
    Friday, April 22, 2011 12:37 PM
  • Hello scorpdevil,

    Thanks for the link but the Office 2010 Backstage has no Commanbars nor CammandbarControls. Using Sub FilePrint() works perfect up to Word 2007, but is history in Word 2010 with the Backstage, as well as using Sub FileNew()

    Regards,
    Lars-Eric

    Friday, April 22, 2011 1:53 PM
  • Thx Scorpdevil. where to write this filePrint() function?
    Krishna Prakash
    Monday, April 25, 2011 10:11 AM
  • Is there any way to hide the complete menu bar in word2010.


    Krishna Prakash
    Thursday, April 28, 2011 5:32 AM
  • Hello Krishna,

    The following XML (from Excel 2007 but works also in 2010) will hide the default RibbonUI, but not the File tab with the Backstage. The startFromScratch attribute in the ribbon tag does the trick. If the value is 'true' the RibbonUI will be completely hidden so when you add your own tabs only those are visible. If set to 'false' your own tabs will be added to the built in tabs. The code snippet below is from a customer document where they want only their own tabs visible.

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
     <ribbon startFromScratch="true">
      <tabs>
       <!-- your own cusom tabs -->
      </tabs>
     </ribbon>
    </customUI>

    Thursday, April 28, 2011 6:41 AM
  • Thanks Larsg_swedon. Could you please provide any code to use this xml in vb?


    Krishna Prakash
    Thursday, April 28, 2011 9:16 AM
  • Hello Krishna,

    Sorry to say, but I think there is no way to programatically to anything about the Ribbon from the automation interface. As far as i know you can only to it by adding the XML code to the document or the template, unless you are using an Add-In but then the modification will global, affect all documents.

    Regards,
    Lasr-Eric

    Thursday, April 28, 2011 9:34 AM
  • In case, if i create a Add-in, can i call that add-in programatically.. So that i call the add-in whenever i need to remove the file menu. once my job is done, i will remove that add-in?


    Krishna Prakash
    Thursday, April 28, 2011 9:41 AM
  • Hello Krishna,

    I'm not sure that it is possible because of the way an Add-In works. Normally it gets loaded when the Office application starts and the RibbonUI is modified at that time. I don't think it's possible to modify the RibbonUI later. An Add-In works very much like a Global Template, which also gets loaded automativally when the Office application starts, but an Add-In is a DLL file and not a Word/Excel/Powerpoint template.

    If you want control over the Ribbon UI from an application that is using the automation interface, I would rekommend using  templates with  modified RibbonUI's and always use your templates when creating new documents from your application. Should work as long as the template is visible to the user.

    Regards,
    Lars-Eric

    Thursday, April 28, 2011 9:52 AM
  • Hi Lars,

    I tried below coding in VB Macro to add the back stage XML.But iam getting the error saying "Required WhiteSpace was missing"

    Below is the code i used,

    Dim StrXML As String
    Dim item As Integer

    StrXML = "<customUI xmlns=" & """" & "http://schemas.microsoft.com/office/2009/07/customui" & """" & ">" & _
     "<backstage>" & _
       "<tab idMso=" & """" & "TabPrint" & """" & "visible=" & """" & "false" & """" & "/>" & _
     "</backstage>" & _
    "</customUI>"

    ThisDocument.CustomXMLParts.Add(StrXML)

    Can you please let me know if there are any issues with the above code..


    Krishna Prakash
    Tuesday, May 17, 2011 11:52 AM
  • Hello Krishna,

    I think the problem is here: & "visible=" &

    Try to add a space infront of the attribute visible:  & " visible=" &
    The way your code creates the string it will be <tab idMso="TabPrint"visible="false"/>
    In the resulting string there must be a space between "TabPrint" and visible=...  : <tab idMso="TabPrint" visible="false"/>

    I hope this helps
    Lars-Eric

    Wednesday, May 18, 2011 6:29 AM
  • Thanks larsg_swedon. I have removed the space and tried, but still print button is visible in word2010. Is there any issue with the XML or VB code?.
    Krishna Prakash
    • Edited by Krishna.133 Wednesday, May 18, 2011 7:01 AM Appended some more..
    Wednesday, May 18, 2011 7:01 AM
  • Hello Krishna,

    Try to find out what your XML string looks like.

     use: msgbox StrXML
    the important part is: <tab idMso="TabPrint" visible="false"/>
    Your code must look like above, including the spaces in the XML. If any of the spaces are missing the code is not valid.

    Look here on MSDN for code examples for adding XML from an Add-In and when to add it.

    Regards,
    Lars-Eric

    Wednesday, May 18, 2011 7:35 AM
  • Hi,

    i tried printing the xml in the message box, it looks as per ur previous comments. but still print button is enabled.

     

    StrXML = "<customUI xmlns=" & """" & "http://schemas.microsoft.com/office/2009/07/customui" & """" & ">" & _
    "<backstage>" & _
       "<tab idMso=" & """" & "TabPrint" & """" & " visible=" & """" & "false" & """" & "/>" & _
     "</backstage>" & _
    "</customUI>"
    MsgBox StrXML

    objWord.ActiveDocument.CustomXMLParts.Add (StrXML)

    If we added also, should we initiate or do we need to do someting?

    Thanks,

    Krishna.


    Krishna Prakash
    Wednesday, May 18, 2011 11:11 AM
  • I tried couple of below things also, None has helped..

    1) StrXML = "<customUI xmlns=" & """" & "http://schemas.microsoft.com/office/2006/01/customui" & """" & " onLoad=" & """" & "OnLoad" & """" & ">" & Chr(10) & _
    " <ribbon startFromScratch=" & """" & "true" & """" & ">" & Chr(10) & _
    "  <tabs>" & Chr(10) & _
    "  </tabs>" & Chr(10) & _
    " </ribbon>" & Chr(10) & _
    "</customUI>"

    MsgBox StrXML

    objWord.ActiveDocument.CustomXMLParts.Add (StrXML)

    2) StrXML = "<customUI xmlns=" & """" & "http://schemas.microsoft.com/office/2006/01/customui" & """" & ">" & Chr(10) & _
    " <ribbon startFromScratch=" & """" & "true" & """" & ">" & Chr(10) & _
    "  <tabs>" & Chr(10) & _
    "  </tabs>" & Chr(10) & _
    " </ribbon>" & Chr(10) & _
    "</customUI>"

    MsgBox StrXML

    objWord.ActiveDocument.CustomXMLParts.Add (StrXML)

    In both of the options, Ribbon control is enabled.

    :(

    Can you please help me on this.


    Krishna Prakash
    Wednesday, May 18, 2011 11:23 AM
  • Hello Krishna,

    Take a look at the following link and check if you are following the same steps as they do on that site.
    http://msdn.microsoft.com/en-us/library/ee691833.aspx#odc_Office2010Introduction2OutSpaceUI_CustomizingOutSpaceUserInterfaceCOMAddIn

    It looks like you are not adding XML code to the RibbonUI/Backstage so follow the steps in the example.

    CustomXMLParts is something different. If I remember correctly you can use Custom XML Parts with XML data and connect the new text controls to the XML data. But modifying the Backstage is something different. If you do it from an Add-In your modifications will be visible to all documents, not on a document level. If you want to modify the backstage for individual documents, you have to modify the Backstage in each document directly and not by code.

    Regards,
    Lasr-Eric

    Wednesday, May 18, 2011 11:35 AM
  • In Excel, below code will hide Ribbon control in Excel 2010

    Application.ExecuteExcel4Macro "SHOW.toolbar(""Ribbon"", False)"

    Is there any similar code for Word2010

    Any help on this will be much helpful.


    Krishna Prakash
    Thursday, May 19, 2011 2:38 PM
  • Hi Calvin,

    Finally, iam able to create a shared com add-in to disable the print button in word 2010. I was able to integrate it with VB also.

    Thanks for your help.


    Krishna Prakash
    Friday, August 5, 2011 2:08 PM
  • Hi Larsg_swedon,

    Can i have a custom xml to disable Save and Save As button in word 2010

    Thanks,

    Krishna


    Krishna Prakash
    Saturday, August 6, 2011 6:38 AM
  • Hello Krishna.

    This XML snippet will disable the Save and Save as button in the Backstage

    <

    customUI xmlns=http://schemas.microsoft.com/office/2009/07/customui>
       <
    backstage>
          <
    button idMso="FileSave" visible="false"/>
          <
    button idMso="FileSaveAs" visible="false"/>
       </
    backstage>
    </
    customUI>

    If you have any further questions to me it may take a few days before I can answer. I'm in Thailand and working on my rice fields for the moment.

    Regards,
    Lars-Eric

    Monday, August 8, 2011 5:52 AM
  • Lars- Thanks for the help. Now iam able to disable Print, Save and Save As button. I can able to enable and disable this Add-in the development machine, but when i try accessing the add-in in another machine, it is showing as

    "not loaded. a runtime error occurred during the loading of the com add-in"

    Can you please help me on this.

    It would be helpful, if you could provide some steps to install the add-in in other machine.

    I followed the below steps.

    1) Took a Addin.dll from the development machine and registered in the target machine.

    2) Ran the registry entry for the add-in.

    When i ran the reg entry, it is showing the add-in name perfectly in Add-ins folder.

    Not sure where iam going wrong. Can u help me.

     


    Krishna Prakash
    Thursday, August 11, 2011 2:02 PM
  • Hello Krishna,

    Have you installed the component correctly on the target machine. The Add-In must be installed correctly on the computer, that means the DLL itself must be correctly registred as a COM component. Search in the registry under HKEY_CLASSES_ROOT\CLSID for the name of the DLL file. If the file name can't be found under a key with a GUID as a key name, the Add-In is not properly installed on the computer.

    Regards,
    Lars-Eric

    Monday, August 15, 2011 6:06 AM
  • Hi Larsg_swedon,

    Now i have created add-in and installed in the user's machine. I have set the registry entry  for Start up behaviour as 2. When iam running the application, the add-in gets loaded into word but the print button is not getting disabled. I have to Check and un-check manually to disable the print button.

    In the code iam setting the .connect property of the add-in as true. But iam setting as True after the word object is loaded. Is this could be a problem.

    Thanks,


    Krishna Prakash
    Thursday, October 6, 2011 3:07 PM
  • Hi Larsg,

    In my VB code, iam performing the below operation to connect and disconnect the add-in.

                If UCase(objWord.COMAddIns.Item(i).Description) = UCase("BackStageCOMAddIn") Then
                    objWord.COMAddIns.Item(i).Connect = True
                    objWord.COMAddIns.Item (i)
                    Exit Function
                End If

    When iam try to load the word for the first time, the print button and save as button are getting disabled. But when iam trying to load the document for the second time, i could see the print button and save as button are visible again. I check for the add-in status. it is in "Active Add-ins Section".

    If i just disable and enable again, it will work. From the code iam not able to achieve this eventhough the Add-in is in active state. 

    Any help?

    Thanks,

    Krishna.


    Krishna Prakash

    Thursday, June 14, 2012 10:45 AM
  • Hello Krishna,

    I really don't understand what you are doing. If the COM-AddIn is correctly installed you should not need to activate it. I tried to create and install a COM-Addin that disabled the Print tab in the Backstage. The tab was disabled never mind how many documents I opened and the callbacks in my AddIn was called correctly from every opened document.

    Is your COM-AddIn solution set up properly with a xxxxxSetUp project that do a correct installation of you component?

    Do you get the same behaviour if you dubug your component from the development environment?

    Regards,
    Lars-Eric

    Thursday, June 14, 2012 12:03 PM