1. Original Entry + Comments2. Write a Comment3. Preview Comment


April 26, 2021  |  Automatically backing up the Normal.dotm file  |  7126 hit(s)

On Twitter recently, DeAnna Burghart reminded us that if you use Microsoft Word, it's important to back up your Normal.dotm file. If the file is overwritten or corrupted, you lose your macros, your keyboard shortcuts, and other goodies that editors rely on.

I've experienced that problem, gah. So a while back, I set up Windows so that it automatically backs up my Normal.dotm file several times a day. I thought it might be useful to show other people how I did this.

Sad note: The information in this post applies only to Windows. I'm sure there's a way to do this on the Mac, probably involving Python or Bash and one of several ways to run a scheduled task.

I realize that this is a long post and therefore looks complicated. It isn't, I promise! I added some extra steps to test as you go to try to make sure that you don't Experience Disappointment.

Update: I created a video version of this tutorial!

Background

To back up your Normal.dotm file, you copy it from its default location (i.e., where Word looks for it) to some other location. AFAIK, the default location is always this:

DRIVE:\Users\YOUR-USER-NAME\AppData\Roaming\Microsoft\Templates

For example, my Normal.dotm file is here:

C:\Users\Mike\AppData\Roaming\Microsoft\Templates

You can certainly copy the file manually. But you can also automate the copy process so that Windows copies the file for you. You might sometimes forget to back up your file by hand, but if you automate the process, you never need to worry about it.

What I did—and what I'll show you here—is that I created a script. The script doesn't just copy the Normal.dotm file to another folder. During the copy process, it names the backup file by adding a date and time stamp. For example, the script creates a file that has a name like this:

Normal(2021-04-26 17_49).dotm

You can see that the filename includes the date (Apr 26, 2021) and time (5:49 pm). Timestamping the backup files has two advantages:

  • Each time you run the backup, you make a new, different backup file. This can be useful if Normal.dotm gets corrupted—you have multiple backup versions of the file, some of which (hopefully) are older than when the corruption occurred.
  • You know when the backup was made.

I use two technologies for the automated backup:

  • PowerShell. This is a programming language that lets you automate Windows tasks like copying files. PowerShell has been in Windows since Windows 7, so you don't need to install anything. I have the complete script in this post, so you don't need to know PowerShell; you can just copy and paste the script.
  • Windows Task Scheduler. This is a Windows utility that lets you run tasks—for example, a script—at specific times or at intervals.

Create the PowerShell script

  1. Create a folder named C:\backup on your computer to copy the backup files to.

    You don't have to use this folder; you can use any folder you like. Just make sure that the folder already exists. (The script won't create it.) If you don't use C:\backup, you need to make some minor changes later.

  2. Open a text editor (for example, Notepad ... don't use Word for this), create a new file, and then copy the following script into it:
    # PowerShell script to back up the Word Normal template (Normal.dotm)
    # 2020-Apr-26 Mike Pope
    
    $bu_path = "C:\backup"
    
    $bu_datetime = Get-Date -Format "yyyy-MM-dd HH_mm"
    $source_file = $env:appdata + "\Microsoft\Templates\Normal.dotm"
    $dest_filename = $bu_path + "\Normal(" + $bu_datetime + ").dotm"
    Write-Output $dest_filename
    Copy-Item -Path $source_file -Destination $dest_filename
  3. If you don't want to use the C:\backup folder, change the path in the third line (the one that starts with $bu_path =). Make sure that you don't add a trailing backslash (\) to your path.
  4. Save the file to the C:\backup folder (or your alternative) using the following name:

    back-up-normal-template.ps1

    The .ps1 extension is used for PowerShell scripts.

  5. Close the text editor.

Test the script

Before you create a scheduled task for the script, it's a good idea to make sure it's working on your computer.

  1. Open a Windows command window. (Press Windows+s, then type CMD). You see a command line:

  2. Enter the following command (better yet, copy and paste it):

  3. powershell.exe -ExecutionPolicy Bypass -File "C:\backup\back-up-normal-template.ps1"

    Again, if you're not using C:\backup, substitute your folder name.

    The command invokes PowerShell and tells it to run the script that's in the back-up-normal-template.ps1 file that you created earlier. The ExecutionPolicy argument tells PowerShell that your script is safe; if you don't include this part, PowerShell will refuse to run the script due to security concerns.

    If all goes well, the script displays the name of the backup file, like this:

    C:\backup\Normal(2021-04-26 17_59).dotm

    If you see red text, read it carefully. Carefully check the command that you entered. You might also need to fix the script itself (the .ps1 file). Some possibilities:

    • The script you used earlier assumes that the Normal.dotm file is in the default location. If the file is in a different location, it's possible the script isn't finding it.
    • If you're not using the C:\backup folder, did you fix up the script to reflect the folder that you are using?

    You must resolve any errors before you can proceed.

  4. If the script appeared to run correctly, look in the C:\backup folder (or the folder you are using instead). Do you see a .dotm file that starts with Normal followed by a date and time? If so, everything is working.

Schedule the backup

You can now configure Windows to run your script at intervals. You do this by creating a scheduled task. When you create the task, you specify what you want to run (the PowerShell command that you just tested) and when you want to run it.

  1. Open the Task Scheduler app. (Press Windows+S, then type Task Scheduler.)

  2. In the folder tree on the left, right-click Task Scheduler Library and then click New Folder. Name the new folder My Tasks. This step isn't essential, but it makes it easier for you to find your custom task later if you want to modify it.

  3. Right-click the My Tasks folder and click Create Task. This opens the Create Task dialog, which has several tabs that you'll be working in.

    Note: Don't close the Create Task dialog (that is, don't click OK), until you've done all the steps.

  4. In the General tab, do the following:

    1. In the Name box, enter the name BackupNormalTemplate.

    2. In the Description box, enter details about what this task is about.

  5. Go to the Actions tab and click New. This is where you specify what you want to run—namely, the PowerShell script.

    1. In the Program/script box, enter powershell.exe.

    2. In the Add arguments box, enter the following:

      -ExecutionPolicy Bypass -File "C:\backup\back-up-normal-template.ps1"

      These settings specify that you want to run the PowerShell script that you tested at the command line earlier.

    3. Click OK to close the New Action dialog and return to the Create Task dialog.

  6. Go to the Triggers tab and click New. This is where you specify when (how often) to run your script.

    1. Under Advanced settings, select the checkbox next to Repeat task every.

    2. Enter an interval for how often you want to run the script. For example, to run the script twice a day, enter 12 hours. (It doesn't look like it, but you can type in that box.)

    3. In the for a duration of list, choose Indefinitely. This tells Windows to keep running the script until you change the interval or delete the scheduled task.

  7. Click OK to close the New Trigger dialog.

  8. In the Create Task dialog box, click OK.

Note: Don't close the Task Scheduler window yet.

Test the scheduled task

You know that the script runs; now you want to make sure that the scheduled task works.

  1. In the Task Scheduler, in the file tree, click the MyTasks folder. The list of scripts in that folder is displayed on the right.

  2. In the right-hand pane, right-click the BackupNormalTemplate task and then click Run.

    The PowerShell scripting window appears briefly, then vanishes.

  3. Go to the C:\backup folder and check that another backup copy of the Normal.dotm file has been saved.

    If this worked, you should be all set.

  4. Close the Task Scheduler app.

You probably want to check the C:\backup folder tomorrow and the next day to make sure that the script is writing out backup files at regular intervals.

If you need to recover a Normal.dotm file, go to the C:\backup folder, rename one of the backup files to just Normal.dotm, and then copy it back to the folder where Word keeps the template.

Hopefully you'll never need to do that. But if you do, you'll have a recent backup available!





EricS   18 Jan 24 - 12:29 AM

Hello Mike,
thanks very much fot these informations. I now have a backup for my normal.dotm file !
by chance, do you have any clue to get back all my macro commands from a corrupted normal.dotm file?
since yesterday MSWord crashes each time I want to access to my macro commands with Alt F11. Same if I tries to get back the macro by the window 'organize" between my previous normal.dotm file and the new one.
my previous backup was one month ago and I worked a lot on the macros since...
thank you again.


 
mike   06 May 24 - 4:35 PM

Hi, Eric. I'm sorry, I didn't see your comment till just now.

Unfortunately, I don't know of a way to recover macros from a corrupted .dotm file. I hope you were able to get the ones you needed. Perhaps this was a question that someone answered on an online forum somewhere?