by Allen Wyatt
(last updated February 12, 2014)
Dianne wonders if there is a way to create a template that will exclude any new styles from being introduced. Clients paste material with formatting and styles into her documents, and that can cause problems. She wants to build a generic template that will create a document that will lock out non-template styles.
This problem has been one that has plagued Word users for years (if not decades). You can spend quite a bit of time getting your template and style sheet just the way you want it, then send it off to someone else only to have it return with the style list (and document formatting) in the electronic equivalent of tatters.
There are several approaches you can take to attempt to remedy the situation. First, you can try the "please don't do that" approach where you simply ask the others to not paste anything into your document. Or, if they must paste something, ask them to use one of the Paste Special variants that allow pasting without formatting.
If you want a more forceful approach, follow these steps:
Figure 1. The Restrict tab of the Manage Styles dialog box.
Theoretically, any document based on the template will restrict what styles the user can use in their formatting. What is unclear is whether this also extends to limiting what styles can be pasted into the document. If you prefer a macro-enforced version of this approach you can use the macros detailed at the following blog:
Of course you could create a set of macros that would stop people from pasting formatted text into a document. (Place the macros in the template on which the document is based and they are passed to the document automatically. Normal caveat: If the user doesn't enable macros, then this approach is of almost no value.)
For example, one approach is to prevent new styles from being added is to determine the number of styles before and after the paste. If the number has increased, then your macro can undo the paste and give the user the options to either paste the Clipboard as plain text or cancel. This method will also prevent styles being introduced from tables and textboxes.
It is important to realize that there is no "general" paste event that can be trapped in VBA. Instead it is necessary to customize several of Word's built-in commands. The following replace four of those commands.
Sub EditPaste() Dim k As Long Options.PasteFormatBetweenDocuments = wdMatchDestinationFormatting Options.PasteFormatBetweenStyledDocuments = wdUseDestinationStyles k = ActiveDocument.Styles.Count Selection.Range.Paste If k <> ActiveDocument.Styles.Count Then ActiveDocument.Undo MsgBox "Paste unsuccessful. You tried to introduce new styles." End If End Sub
Sub EditPasteSpecial() Dim k As Long Dim lk As Boolean Options.PasteFormatBetweenDocuments = wdMatchDestinationFormatting Options.PasteFormatBetweenStyledDocuments = wdUseDestinationStyles k = ActiveDocument.Styles.Count With Dialogs(wdDialogEditPasteSpecial) .Show lk = .link End With If lk Then ActiveDocument.Undo MsgBox "You are not allowed to paste links" Exit Sub End If If k <> ActiveDocument.Styles.Count Then ActiveDocument.Undo If MsgBox("You have tried to introduce new styles." & vbCrLf & _ "Do you want to paste as plain text?", vbYesNo) = vbYes Then _ Selection.Range.PasteSpecial datatype:=wdPasteText End If End Sub
Sub PasteDestinationFormatting() Dim k As Long k = ActiveDocument.Styles.Count Selection.Range.Paste If k <> ActiveDocument.Styles.Count Then ActiveDocument.Undo MsgBox "Paste unsuccessful. You tried to introduce new styles." End If End Sub
Sub PasteSourceFormatting() MsgBox "You are not allowed to paste with source formatting" End Sub
Another non-macro approach is to change the protection for the document. With the template loaded into Word, follow these steps:
Figure 2. The Formatting Restrictions dialog box.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12698) applies to Microsoft Word 2007, 2010, and 2013.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
Double-click a Word template file in Windows, and Word should create a brand new document based on that template. If this ...Discover More
If you've opened a document in Word, that document has a template attached to it. This tip looks at what those templates do ...Discover More
Templates are used to store a pattern for how a document should look. As such, they can be a very powerful tool for creating ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.