Limiting Printing to a Workbook from a Set Location

Written by Allen Wyatt (last updated September 18, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


1

Stefano is having a problem in his company where people will often copy a workbook from the server to their own computer, make changes in the workbook, and then print the workbook. He would like to enforce that only the original workbook is allowed to be printed, so he wonders if there is a way to prohibit printing unless the workbook is the one on the server.

There is no native way to do this in Word. You could, if desired, create a macro that did the following two things:

  1. Examine the path for the current document
  2. If the path is anything except the path for your server, prohibit printing

Here's an example of such a macro. You should place this particular version in the ThisWorkbook module; it automatically runs every time the user chooses to print.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Dim sFile As String

    sFile = "\\Server.name\folder\path\My file name.xlsm"

    If ThisWorkbook.FullName <>  sFile Then
        MsgBox "Printing only possible with server copy"
        Cancel = True
    End If
End Sub

Note that the sFile variable is set to contain the full path to the workbook (to where the workbook should be located on the company server). If the name of the current workbook doesn't match this, then printing is disabled.

There is a potential problem with this type of macro, and it has to do with the path to the file. It is possible that the path for the server may differ on a user-by-user basis. The example macro checks for a path that includes a UNC (Universal Naming Convention), but not all paths might work this way. For instance, users might have the folder on the server mapped to a drive letter. On one system the path might be g:/myserver/myfolder/ and on another it might be z:/myserver/myfolder/. The macro cannot reliably compensate for this.

You might be able to get around this with a definitely low-tech approach. First, put a small text file (created with Notepad) into the same folder on the server as the workbook. It isn't really important what the text file contains. Then, add this macro to your ThisWorkbook module:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Dim sPath As String
    Dim sFile As String

    sPath = ThisWorkbook.Path
    sFile = sPath & "\" & "TestFile.txt"

    If Dir(sFile) = "" Then
        MsgBox "Printing only possible with server copy"
        Cancel = True
    End If
End Sub

What the macro does is to determine the path of the currently open workbook. This is then added to the name of the small text file you placed in the same folder as the workbook. (In this case, I've given this file the name TestFile.txt.) The Dir command is then used to see if the file exists. If it doesn't exist, then the printing is cancelled.

A more encompassing solution might be to use what Microsoft refers to as IRM (Information Rights Management). This solution, which is well suited for use in a corporate environment, allows you to control what people can and cannot do with your documents. A good place to start learning about IRM is here:

https://support.office.com/en-us/article/information-rights-management-in-office-c7a70797-6b1e-493f-acf7-92a39b85e30c

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13526) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Quick and Dirty Paragraph Count

Need to know how many paragraphs are in a document? You can use Word's Find and Replace feature to get a count quickly.

Discover More

Unable to Use Bulleting and Numbering

Got a document where you just can't get bullets and numbering to work right? It could be that your document is corrupted. ...

Discover More

Entering a Name in the Header of a Locked Form

When you lock a document as a form, then Word limits what you can do with that document. That includes not being able to ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Printing Odd or Even Pages

When you print a worksheet, Excel normally prints all the pages or a consecutive series of pages that you specify. If you ...

Discover More

Setting Print Quality

When printing information in a workbook, you may want to take advantage of the different print quality settings available ...

Discover More

Printing without Opening

Want to print one or more workbooks without the need of actually opening the file? It's easy to do when you rely on ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 6 - 0?

2018-05-12 17:19:08

Adam Nimmo

I have a similar problem to Stefano with the job lists for factory shutdowns. People often print files that have been sent as attachments to emails and at meetings their job numbers may be different to others with the official version of the file that is on the server.

There could be another option if the file being printed has a path that does not match the specified path and that is to force a warning message header or footer into every file that is not on the original path warning that this is not the most recent version or not the official version of the file but still allow it to print.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.