Search code examples
vbalayoutms-wordms-officeribbon

Word add-in, custom layout


Is it possible to create a custom layout, existing ones are:

  • Print layout
  • Full Screen reading
  • Web layout
  • Outline
  • Draft

These can be found in the View Ribbon under the group Document Views.

My aim is to get my own layout button in either the existing View Ribbon (if it is possible to modify it) or add a new layout to my custom Ribbon.

Thanks in advance!


Solution

  • This answer is going to provide information on how to change standard settings of any view type control and associate these changes with certain document. This will not work with all documents and will not change the control action for whole Word Application but for one document. Operation could be repeated for few document and almost all Word button.

    Important! I'm not using English version of Office application therefore some description will not match exactly to what you have. Tried and tested for Word 2010.

    There are following steps to go:

    1. Open new document- one where control should work according to your private expectations.
    2. Go to View >> Macros >> Show list of macros
    3. In the combo-box below middle of the Macro window choose something like Word application commands (or Word macros or similar). As a result you get list of lots of macros names.
    4. You need to guess which of the macro is associated with ribbon control you are going to change. Use common sense and logic to find it. Sometimes two or three seems to match and possibly you will need to make a try.

      A) let's try to change behaviour of draft/pending/working view ribbon control. one rounded red below:

      enter image description here

      B) find macro ViewNormal (but not ViewDraft)

      C) select this macro on the list

    5. Change back on the combo-box list to your document (while keeping your chosen macro selected)

    6. Press Create button on the right in the macro window. You will be moved to VBA Editor to the following code:

      Sub ViewNormal()
      '
      ' ViewNormal Makro
      ' Zmienia widok edycji na normalny
      '
          If ActiveWindow.View.SplitSpecial = wdPaneNone Then
              ActiveWindow.ActivePane.View.Type = wdNormalView
          Else
              ActiveWindow.View.Type = wdNormalView
          End If
      
      End Sub
      

      This code is responsible for working of chosen ribbon control.

    7. First, let's check if we can take control of ribbon button- add MsgBox "Control taken" at the end of the code, before End sub. Back to Word App and press button on the ribbon which result should be- setting of chosen view and our message box.

    8. Now you need to change your code accordingly to set your view as you need. Use VBA for that.

    9. Save document as .Docm and all the changes will be applied to the document each time you press chosen ribbon button.