Queens Dev
Some more ASP.NET

VBScript to Change AutoText in Word 2003 Normal.dot

March 20, 2008 at 1:17 AM by bjsetegn

My client recently changed there name for branding reasons, making it more concise.  They have around 100 employees using Word with an Autotext (auto complete) entry for their old company name.  For anyone who doesn't already know what the Autotext feature is in Word it is a special feature that will complete a phrase for you after you type the first couple of letters for it.  This actual text for the Autotext is stored in the Normal.Dot file located deep within your file systems  which is the default Word template.  This template is loaded every time you open a new document.  Outlook also uses Word as its editor and thus uses the Normal.dot.  

Anyway, they wanted to change the Autotext entry for their company name on all 100 computers.  This would have been quite a hassle for each user to do themselves or taken a lot of time for one person to run around to each computer and change it.  So they had me write a script that would change the entry and could be set to run the next time the user logged in.  At first I tried to edit the Normal.dot file manually through a filestream but I ran into problems when writing the changes back.  Special characters and other items in the file header were either erased or changed and the file would be corrupted.  So I reached out for some help and an IT guy sent me a link to some code that looked a lot like what I have below (I can't find the link or I would post it, only half of what's below I will claim as my own work, the easy half).  I modified it to work for my situation and added some error checking in case it was run more than once and the old record wasn't found.  It worked pretty well and for once I was assured I had saved the client some money.  Oh how powerful vbscript can be.

To run the code save the text below to a text file such as RenameAutotext.vbs.  Then from the command prompt run: cscript RenameAutotext.vbs.  Run using cscript not wscript because if run using wscript will send the Echo command to the program running, Word, instead of writing it to the command line.  This script is also test to work only for Windows XP and Microsoft Word 2003.  Word 2007 uses a different type of template file so and this script will need to be modified to work with that.

There may be some extraneous parts that aren't 100% necessary below but with vbscript I am happy when I get it to do exactly what I want and leave it at that.  If anyone has some suggestions for improvement leave a comment. 

The Code: 

    'Rename an

    'Get Application Data Path

    Set oShell = CreateObject("WScript.Shell")

    appdata = oShell.ExpandEnvironmentStrings("%APPDATA%")

 

    Set objWord = CreateObject("Word.Application")

    objWord.Visible = True

 

    Set objDoc = objWord.Documents.Open(appdata & "\Microsoft\Templates\Normal.dot", False)

 

    'Add new autotext entries

    Set objTxtEntry = objWord.NormalTemplate.AutoTextEntries.Add("New Company Name", objWord.Selection.Range)

    objWord.NormalTemplate.AutoTextEntries("New Company Name").Value = "New Company Name"

 

    'Enable error handling

    On Error Resume Next

    'Delete old autotext entries

    objWord.NormalTemplate.AutoTextEntries("Old Company Name").Delete

 

    If Err.Number <> 0 Then

        WScript.Echo "No Old Company Name record found, new entry inserted."

    Else

        WScript.Echo "Completed Successfully."

    End If

 

    'Print all autotext entires to make sure it was changed properly

    'Wscript.Echo

    Dim i

    For Each i In objWord.NormalTemplate.AutoTextEntries

       Wscript.Echo i.Name

    Next

 

    objWord.Quit

 

Comments

April 21. 2009 18:57

saç ekimi

good article.

saç ekimi

June 28. 2009 18:28

婚活パーティー検索

thanks for the code.

婚活パーティー検索

February 26. 2010 01:31

payday loans

Hitch your wagon to a star.

payday loans

March 1. 2010 15:05

Logan Zieglen

Howdy that’s a very fascinating view, It does give one food for thought, I am genuinely delighted I stumbled on your blog, i was using Stumbleupon at the time, in any case i don’t want to drift on too much, but i would like to mention that I will be back when I have a little time to read your blog more thoroughly, Once again thank you  for the blog post and please do keep up the good work,

Logan Zieglen

March 2. 2010 03:24

Refurbished Computers

Well, I have been reading your blog posts daily and the reason I come on your blog frequently is its compelling content… Regards… http://www.pctechoutlet.com

Refurbished Computers

March 3. 2010 04:10

how to cure genital warts

Genital warts can be cured by the tapping up of figs, fresh plants and concentrate over the skin for several hours in a day.

how to cure genital warts

March 3. 2010 06:46

consolidating credit card debt

Hello. This is kind of an "unconventional" question , but have other visitors asked you how get the menu bar to look like you've got it? I also have a blog and am really looking to alter around the theme, however am scared to death to mess with it for fear of the search engines punishing me. I am very new to all of this ...so i am just not positive exactly how to try to to it all yet. I'll just keep working on it one day at a time Thanks for any help you can offer here.

consolidating credit card debt

March 3. 2010 16:16

personal trainer certification online

thanks!

personal trainer certification online

March 7. 2010 16:33

Ulysses Lopresti

This is appealing to me. I 'll be looking forward to future articles.

Ulysses Lopresti

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading