{"id":66063,"date":"2006-11-10T21:34:00","date_gmt":"2006-11-10T21:34:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/11\/10\/how-can-i-change-the-default-highlight-color-for-a-microsoft-word-document\/"},"modified":"2006-11-10T21:34:00","modified_gmt":"2006-11-10T21:34:00","slug":"how-can-i-change-the-default-highlight-color-for-a-microsoft-word-document","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-change-the-default-highlight-color-for-a-microsoft-word-document\/","title":{"rendered":"How Can I Change the Default Highlight Color for a Microsoft Word Document?"},"content":{"rendered":"<p><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"><\/p>\n<p>Hey, Scripting Guy! How can I change the default highlight color for a Microsoft Word document?<\/p>\n<p>&#8212; TW<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/a><\/p>\n<p>Hey, TW. You know, any time the Scripting Guy who writes this column wants to terrify the Scripting Son, he tells the blood-curdling saga of the first TV the Scripting Dad remembers: a TV that showed everything in black-and-white only! Granted, that was a long time ago, and the Scripting Dad has only vague memories of that TV; not too long after he was born his Scripting Parents bought a color TV. But it was real nonetheless, and just the thought of having to watch everything in black-and-white is enough to give the Scripting Son the heebie-jeebies.<\/p>\n<p>And no, the Scripting Dad doesn\u2019t mention the fact that there were no remote controls in those days, either. It\u2019s one thing to give the Scripting Son a little scare every now and then; it\u2019s quite another thing to terrify and traumatize the poor kid.<\/p>\n<table id=\"E3C\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\"><b>Note<\/b>. We also should point out that the fact that the Scripting Dad has only vague memories of this TV doesn\u2019t mean that all of this happened hundreds of years ago. After all, the Scripting Dad has only vague memories of what he had for breakfast this morning, despite the fact that \u2013 Mondays through Fridays \u2013 he pretty much has the same thing for breakfast <i>every<\/i> morning.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>The important thing here \u2013 beyond the fact that kids these days have no idea how good they really have it \u2013 is the fact that color is important, regardless of whether we\u2019re talking about TVs or Microsoft Word documents. So can you change the default highlight color for a Word document? Well, as long as you start that document with a script you can:<\/p>\n<pre class=\"codeSample\">Const wdBrightGreen = 4\nSet objWord = CreateObject(\"Word.Application\")\nSet objDoc = objWord.Documents.Add()\nSet objOptions = objWord.Options\nobjOptions.DefaultHighlightColorIndex = wdBrightGreen\nobjWord.Visible = True\n<\/pre>\n<p>As you can see, we start out by defining a constant named wdBrightGreen and assigning it the value 4. Needless to say, we do that because we want to set the default highlight color to bright green. (Hey, when you start out life watching TV in black-and-white <i>any<\/i> color looks good, even bright green.) What if you consider bright green to be a bit garish? No problem; you can use any of the constants and values shown in the following table:<\/p>\n<table id=\"ERD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\"><b>Constant<\/b><\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\"><b>Value<\/b><\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdAuto<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdBlack<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdBlue<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdBrightGreen<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">4<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdByAuthor<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">-1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdDarkBlue<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">9<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdDarkRed<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">13<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdDarkYellow<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">14<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdGray25<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">16<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdGray50<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">15<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdGreen<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">11<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdNoHighlight<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdPink<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">5<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdRed<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">6<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdTeal<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">10<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdTurquoise<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">3<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdViolet<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">12<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdWhite<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">8<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">wdYellow<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">7<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>After defining the constant we use these two lines of code to create an instance of the <b>Word.Application<\/b> object and open a new, blank document:<\/p>\n<pre class=\"codeSample\">Set objWord = CreateObject(\"Word.Application\")\nSet objDoc = objWord.Documents.Add()\n<\/pre>\n<p>As soon as we have a document we\u2019re ready to change the default highlight color. To do that we need to do two things: 1) create an instance of Word\u2019s <b>Options<\/b> object, and 2) assign the constant wdBrightGreen to the Option object\u2019s <b>DefaultHighlightColorIndex<\/b> property. That\u2019s what we do here:<\/p>\n<pre class=\"codeSample\">Set objOptions = objWord.Options\nobjOptions.DefaultHighlightColorIndex = wdBrightGreen\n<\/pre>\n<p>That\u2019s all we have to do. If we make our instance of Word visible (which we do, in the last line of the script) and if you look on the toolbar you\u2019ll see that the default highlight color is now bright green. How \u2018bout <i>that<\/i>?<\/p>\n<p>What the preceding script does is set the default highlight color; if you now manually highlight text in a Word document and then click the highlight button that text will be highlighted in bright green. However, if you want to highlight text programmatically you don\u2019t need to set the default highlight color. Instead, you can use a script similar to this:<\/p>\n<pre class=\"codeSample\">Const wdBrightGreen = 4\nSet objWord = CreateObject(\"Word.Application\")\nSet objDoc = objWord.Documents.Add()\nobjWord.Visible = True\nSet objSelection = objWord.Selection\nobjSelection.TypeText \"Here is text that is not highlighted.\"\nobjSelection.TypeParagraph()\nobjSelection.Range.HighlightColorIndex = wdBrightGreen\nobjSelection.TypeText \"And here's text highlighted in green\"\nobjSelection.TypeParagraph()\n<\/pre>\n<p>Let\u2019s see if we can quickly run through this script and figure out what it does. We start out \u2013 again \u2013 by defining a constant named wdBrightGreen and setting the value of that constant to 4. We then create an instance of Word, add a new document, and then make that instance of Word visible onscreen. That\u2019s all old hat by now. (Isn\u2019t it?)<\/p>\n<p>Our next step is to create an instance of the Word <b>Selection<\/b> object, then use the <b>TypeText<\/b> and <b>TypeParagraphs()<\/b> methods to type a paragraph (a paragraph of non-highlighted text) into our document. That\u2019s what we do here:<\/p>\n<pre class=\"codeSample\">Set objSelection = objWord.Selection\nobjSelection.TypeText \"Here is text that is not highlighted.\"\nobjSelection.TypeParagraph()\n<\/pre>\n<p>What we want to do now is type in some text that <i>is<\/i> highlighted. To accomplish that feat all we need to do is use the Selection object\u2019s <b>Range<\/b> object and set the value of the <b>HighlightColorIndex<\/b> property to wdBrightGreen:<\/p>\n<pre class=\"codeSample\">objSelection.Range.HighlightColorIndex = wdBrightGreen\n<\/pre>\n<p>Until we tell the Range object something different, all the text we type from this point on will be highlighted in bright green. In fact, when our script finishes running our Word document will look like this:<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Microsoft Word\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/wordhighlight.jpg\" width=\"327\" height=\"329\"><\/p>\n<p>Cool, huh? To turn highlighting off just set the HighlightColorIndex to 0:<\/p>\n<pre class=\"codeSample\">objSelection.Range.HighlightColorIndex = 0\n<\/pre>\n<p>Hope that helps, TW. As for the Scripting Son, well, we\u2019re going to go easy on him. We thought about telling him about bottles of Pepsi that couldn\u2019t be opened by hand but required a bottle opener instead. Or maybe the fact that, way back when, you could only watch cartoons on Saturday mornings; there was no such thing as 24-hour cartoon channels. But that would be just plain mean, wouldn\u2019t it?<\/p>\n<p>Besides, he probably wouldn\u2019t believe us anyway.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I change the default highlight color for a Microsoft Word document? &#8212; TW Hey, TW. You know, any time the Scripting Guy who writes this column wants to terrify the Scripting Son, he tells the blood-curdling saga of the first TV the Scripting Dad remembers: a TV that showed everything [&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-66063","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 change the default highlight color for a Microsoft Word document? &#8212; TW Hey, TW. You know, any time the Scripting Guy who writes this column wants to terrify the Scripting Son, he tells the blood-curdling saga of the first TV the Scripting Dad remembers: a TV that showed everything [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66063","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=66063"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66063\/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=66063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=66063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=66063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}