{"id":65773,"date":"2007-01-09T06:32:00","date_gmt":"2007-01-09T06:32:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/01\/09\/hey-scripting-guy-how-can-i-add-a-new-item-to-the-microsoft-office-word-autocorrect-list\/"},"modified":"2007-01-09T06:32:00","modified_gmt":"2007-01-09T06:32:00","slug":"hey-scripting-guy-how-can-i-add-a-new-item-to-the-microsoft-office-word-autocorrect-list","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-add-a-new-item-to-the-microsoft-office-word-autocorrect-list\/","title":{"rendered":"Hey, Scripting Guy! How Can I Add a New Item to the Microsoft Office Word AutoCorrect List?"},"content":{"rendered":"<h2><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" class=\"nearGraphic\" \/> <\/h2>\n<p>Hey, Scripting Guy! How can I add a new item to Office Word&rsquo;s AutoCorrect list?<\/p>\n<p>&#8212; OK<\/p>\n<p><img decoding=\"async\" height=\"5\" width=\"5\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" alt=\"Spacer\" border=\"0\" \/><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" class=\"nearGraphic\" \/><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" height=\"288\" width=\"120\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" align=\"right\" alt=\"Script Center\" border=\"0\" title=\"Script Center\" class=\"farGraphic\" \/><\/a><\/p>\n<p>Hey, OK. To begin with, we should point out that we have no way of knowing whether your initials really are O and K; after all, they could just as easily be TR, and you could actually be Tony Romo, quarterback of the Dallas Cowboys, writing to us under an assumed name. (Which, if you value your reputation, is the <i>only<\/i> kind of name you should use when writing to the Scripting Guys.) If that&rsquo;s the case, then we want you to know that we have nothing against you personally. (Granted, we&rsquo;ll never be convinced that you deserved to make the Pro Bowl this year, but that&rsquo;s not really your fault.) Having said that, however, it&rsquo;s also true that we <i>do<\/i> have all sorts of things against the Dallas Cowboys. Because of that we&rsquo;re actually quite happy that your fumbled snap helped ensure that the Cowboys lost to the Seattle Seahawks in the opening round of the NFL playoffs. Thanks, man!<\/p>\n<table cellpadding=\"0\" cellspacing=\"0\" class=\"dataTable\" id=\"ECD\">\n<thead><\/thead>\n<tbody>\n<tr valign=\"top\" class=\"record\">\n<td>\n<p><b>Note<\/b>. Yes, we know: every religion ever created tells us that we should love thy neighbor. On the other hand, most religions are pretty old and were established long before there was such a thing as the Dallas Cowboys. If someone started a new religion today things might be different.<\/p>\n<p>Besides, it&rsquo;s not like we&rsquo;re the only ones who don&rsquo;t like the Cowboys; heck, even many of the <i>Cowboy<\/i> players don&rsquo;t seem to like the Cowboys. The Scripting Guys are just trying to go along with the crowd.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>Anyway, if it turns out that you <i>are<\/i> Tony Romo, well, yes, we are reveling in your misfortune, and we do feel a <i>little<\/i> bad about that. (Not much, mind you, but a little.) But while Saturday&rsquo;s defeat means that you won&rsquo;t get a Super Bowl ring this year, here&rsquo;s something equally valuable: a script that adds a new item to Word&rsquo;s AutoCorrect list:<\/p>\n<pre class=\"codeSample\">Set objWord = CreateObject(\"Word.Application\")<br \/>objWord.Visible = True<\/pre>\n<pre class=\"codeSample\">Set colEntries = objWord.AutoCorrect.Entries<br \/>colEntries.Add \"Fabirkam\", \"Fabrikam\"<\/pre>\n<p>And no, this script isn&rsquo;t four lines long because we refused to write more than four lines of code for the Dallas Cowboys. On the contrary: we have just four lines of code simply because all we <i>need <\/i>is four lines of code. That&rsquo;s all it takes to add an item to the AutoCorrect list.<\/p>\n<table cellpadding=\"0\" cellspacing=\"0\" class=\"dataTable\" id=\"EAE\">\n<thead><\/thead>\n<tbody>\n<tr valign=\"top\" class=\"record\">\n<td>\n<p class=\"lastInCell\"><b>Note<\/b>. So does that mean that if we <i>did<\/i> need more than four lines of code we would have gone ahead and done that extra work? Uh, sure, sure we would have. Hey, you know how the Scripting Guys feel about doing extra work.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>As you can see, the script starts out by creating an instance of the <b>Word.Application<\/b> object, then sets the <b>Visible<\/b> property to True; that gives us a running instance of Word that we can see on screen. Note that you don&rsquo;t <i>have<\/i> to make Word visible in order to add an item to the AutoCorrect list; if you want, go ahead and leave out the line of code that sets the Visible property to True. If you elect to do that just be sure to make this the last line of the script:<\/p>\n<pre class=\"codeSample\">objWord.Quit<\/pre>\n<p>And yes, that <i>is<\/i> important: if you omit the <b>Quit<\/b> method Word will not terminate when the script ends, but will, instead, continue to run on forever and ever.<\/p>\n<p>Sort of like the Dallas Cowboys&rsquo; playoff losing streak, which has now reached 10 years and counting.<\/p>\n<p>Not that we&rsquo;re counting, mind you.<\/p>\n<p>As soon as Word is up and running we use this line of code to create an object reference to the <b>AutoCorrect.Entries<\/b> collection:<\/p>\n<pre class=\"codeSample\">Set colEntries = objWord.AutoCorrect.Entries<\/pre>\n<p>From there all we need to do is call the <b>Add<\/b> method to add a new item to the collection:<\/p>\n<pre class=\"codeSample\">colEntries.Add \"Fabirkam\", \"Fabrikam\"<\/pre>\n<p>As you can see, the Add method takes two parameters: <i>Fabirkam<\/i> (the common misspelling that we want to correct) and <i>Fabrikam<\/i> (the corrected spelling). From now on anytime we type <i>Fabirkam<\/i> Word will autocorrect the spelling the <i>Fabrikam<\/i>.<\/p>\n<p>What if we change our mind and decide that we don&rsquo;t want <i>Fabirkam <\/i>in the AutoCorrect list after all? No problem; here&rsquo;s a simple little script that binds to the AutoCorrect.Entries collection, looks for an entry with the <b>Name<\/b><i><\/i>Fabirkam, then uses the <b>Delete<\/b> method to remove that item from the collection:<\/p>\n<pre class=\"codeSample\">Set objWord = CreateObject(\"Word.Application\")<br \/>objWord.Visible = True<\/pre>\n<pre class=\"codeSample\">Set colEntries = objWord.AutoCorrect.Entries<\/pre>\n<pre class=\"codeSample\">For Each objEntry in colEntries<br \/>    If objEntry.Name = \"Fabirkam\" Then<br \/>        objEntry.Delete<br \/>    End If<br \/>Next<\/pre>\n<p>And yes, we have no doubt the Dallas Cowboys wish it was as easy to undo the actions of a football play as it is to undo the actions of the script. But the Scripting Guys would never say something like that; after all, the Cowboys probably feel bad enough without us rubbing it in.<\/p>\n<table cellpadding=\"0\" cellspacing=\"0\" class=\"dataTable\" id=\"ENG\">\n<thead><\/thead>\n<tbody>\n<tr valign=\"top\" class=\"record\">\n<td>\n<p class=\"lastInCell\"><b>Note<\/b>. Besides, now the Seahawks have to travel to Chicago to take on the Bears, which means that the Cowboys shouldn&rsquo;t worry too much: we&rsquo;re likely to get our comeuppance soon enough. (But, hey, you never know, right?) Go Seahawks!<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I add a new item to Office Word&rsquo;s AutoCorrect list? &#8212; OK Hey, OK. To begin with, we should point out that we have no way of knowing whether your initials really are O and K; after all, they could just as easily be TR, and you could actually be [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[84,49,3,5],"class_list":["post-65773","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-microsoft-word","tag-office","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I add a new item to Office Word&rsquo;s AutoCorrect list? &#8212; OK Hey, OK. To begin with, we should point out that we have no way of knowing whether your initials really are O and K; after all, they could just as easily be TR, and you could actually be [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/65773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=65773"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/65773\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=65773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=65773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=65773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}