{"id":53753,"date":"2009-05-14T23:23:00","date_gmt":"2009-05-14T23:23:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/05\/14\/hey-scripting-guy-how-can-i-use-windows-powershell-to-look-for-and-replace-a-word-in-a-microsoft-word-document\/"},"modified":"2009-05-14T23:23:00","modified_gmt":"2009-05-14T23:23:00","slug":"hey-scripting-guy-how-can-i-use-windows-powershell-to-look-for-and-replace-a-word-in-a-microsoft-word-document","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-use-windows-powershell-to-look-for-and-replace-a-word-in-a-microsoft-word-document\/","title":{"rendered":"Hey, Scripting Guy! How Can I Use Windows PowerShell to Look for and Replace a Word in a Microsoft Word Document?"},"content":{"rendered":"<h2><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\" \/> <\/h2>\n<p>Hey, Scripting Guy! The <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/all.mspx\" target=\"_blank\">week of April 17, 2009<\/a>, you did a weeklong series of \u201cHey, Scripting Guy!\u201d articles on regular expressions. I tried to change one of your scripts to open an office Word document that uses Windows PowerShell to look for a particular word. Guess what? It did not work. Instead, it filled my screen with gibberish, the speakers started beeping &#8220;dah, dah, beep, beep, beeep,&#8221; and the computer became unresponsive. Do I have to get a new version of Windows PowerShell? Do I have a virus? What&#8217;s going on?<\/p>\n<p>&#8211; KL<\/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\" \/> <\/p>\n<p>Hi KL,<\/p>\n<p>You know, diagnosing computer problems via e-mail is like doing brain surgery over the Internet. It might sound like a good idea at the time. It is also really tricky to do well. And the unintended consequences could be rather severe. However, I will venture a guess. Either you accidentally clicked on the song <a href=\"http:\/\/en.wikipedia.org\/wiki\/Men_at_Work\" target=\"_blank\">&#8220;Down Under&#8221;<\/a> by Men at Work (one of my favorite songs by the way), or you tried to open a Word document that uses the <b>Get-Content<\/b> cmdlet. This last observation is not as <a href=\"http:\/\/en.wikipedia.org\/wiki\/Kreskin\" target=\"_blank\">Kreskinesque<\/a> as you might think, because you already said this is what you did. The thing is that the <b>Get-Content<\/b> cmdlet is great at opening and reading text files, but it does not do as well with other file formats. All the beeping is occurring when <b>Get-Content<\/b> tries to convert the strange data to ASCII. This causes the speaker to beep every time that it hits hexadecimal 7. Here\u2019s the gibberish created by trying to read a .doc file:<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Image of the gibberish created by trying to read a .doc file\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/may\/hey0514\/hsg-05-14-09-01.jpg\" width=\"500\" height=\"427\" \/> <\/p>\n<p>&nbsp;<\/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\">This week we are looking at how to migrate VBScript to Windows PowerShell. You should definitely check out the <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/winpsh\/convert\/default.mspx\" target=\"_blank\">VBScript-to-Windows PowerShell Conversion Guide<\/a>. This is included as Appendix C in the Microsoft Press book, <a href=\"http:\/\/www.microsoft.com\/MSPress\/books\/authors\/auth10329.aspx\" target=\"_blank\">Microsoft Windows PowerShell Step by Step<\/a>. It is also in the <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/winpsh\/pschm.mspx\" target=\"_blank\">Windows PowerShell Graphical Help File<\/a>. Clearly, we are proud of that thing. You may also want to check out our <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\" target=\"_blank\">Windows PowerShell Scripting Hub<\/a> where you will find links to the Windows PowerShell Owner&#8217;s Manual (very popular!) and other resources that will help you to convert VBScript to Windows PowerShell. One additional book that would be useful is the Microsoft Press book, <a href=\"http:\/\/www.microsoft.com\/MSPress\/books\/authors\/auth9541.aspx\" target=\"_blank\">Windows PowerShell Scripting Guide<\/a>. This book is useful if you are working with WMI, or if you are trying to go beyond simple line-by-line translations of one script to another.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>There was a good \u201cHey, Scripting Guy!\u201d article written on August 8, 2006, called <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/aug06\/hey0808.mspx\" target=\"_blank\">&#8220;How can I replace text in a Microsoft Word document?&#8221;<\/a> Of course back in 2006, all scripts on the Script Center were being written in VBScript. Let&#8217;s consider translating it to Windows PowerShell. The original VBScript is seen here:<\/p>\n<p><b>ReplaceWordinWord.vbs<\/b><\/p>\n<p class=\"CodeBlockScreened\"><font face=\"Lucida Sans Typewriter\">Const wdReplaceAll = 2<\/p>\n<p>Set objWord = CreateObject(&#8220;Word.Application&#8221;)<br \/>objWord.Visible = True<\/p>\n<p>Set objDoc = objWord.Documents.Open(&#8220;C:\\Scripts\\Test.doc&#8221;)<br \/>Set objSelection = objWord.Selection<\/p>\n<p>objSelection.Find.Text = &#8220;&lt;computername&gt;&#8221;<br \/>objSelection.Find.Forward = TRUE<br \/>objSelection.Find.MatchWholeWord = TRUE<\/p>\n<p>objSelection.Find.Replacement.Text = &#8220;atl-ws-01&#8221;<\/p>\n<p>objSelection.Find.Execute ,,,,,,,,,,wdReplaceAll<\/font><\/p>\n<p>The <b>ReplaceWordinWord.ps1<\/b> script resembles the <b>ReplaceWordinWord.vbs<\/b> script. The one change we made to the Windows PowerShell version is using variables for the eleven parameters that are used in this script for the <b>Execute<\/b> method. This is something that was a recommended technique for VBScript as well. It is just virtually impossible for most IT pros to be able to examine a line such as this one and be able to quickly tell which position the <b>wdReplaceAll<\/b> constant is occupying. Most students, I found while teaching, had problems even counting the padding in front of <b>wdReplaceAll<\/b>. It is too easy to lose your position when all the little commas begin to run together, as shown here: <\/p>\n<pre class=\"codeSample\">objSelection.Find.Execute ,,,,,,,,,,wdReplaceAll<\/pre>\n<p>In the <b>ReplaceWordInWord.ps1<\/b> script, we replace that section of the code with the following code, which is much easier to read:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">objSelection.Find.Execute($FindText,$MatchCase,<br \/><span>&nbsp; <\/span>$MatchWholeWord,$MatchWildcards,$MatchSoundsLike,<br \/><span>&nbsp; <\/span>$MatchAllWordForms,$Forward,$Wrap,$Format,<br \/><span>&nbsp; <\/span>$ReplaceText,$ReplaceAll)<\/font><\/span><\/p>\n<p>If this is still too jumbled, you could spread it out so that each parameter was on its own line. We tried to group the parameters together so that related parameters are on the same line.<\/p>\n<p>The <b>ReplaceWordInWord.ps1<\/b> script begins by creating an instance of the <b>Word.Application<\/b> object. Then it sets the <b>visible<\/b> property to <b>$true<\/b> and opens the Word document. As soon as the document is open, it creates a <b>selection<\/b> object. The <b>Word.Application<\/b> object and the <b>Selection<\/b> object were both discussed <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/may09\/hey0513.mspx\" target=\"_blank\">on Wednesday<\/a>. This is shown here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">$objWord = New-Object -ComObject word.application<br \/>$objWord.Visible = $True<br \/>$objDoc = $objWord.Documents.Open(&#8220;C:\\fso\\test.doc&#8221;)<br \/>$objSelection = $objWord.Selection<\/font><\/span><\/p>\n<p>The text.doc document, as shown here, has some misspelled words:<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Image of misspelled words in the text.doc document\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/may\/hey0514\/hsg-05-14-09-02.jpg\" width=\"500\" height=\"358\" \/> <\/p>\n<p>&nbsp;<\/p>\n<p>The text that the script looks for is stored in the <b>$findText<\/b> variable. The replacement text is contained in the <b>$ReplaceText<\/b> variable. This is seen here. <\/p>\n<pre class=\"codeSample\"><p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">$FindText = \"mispelled\"<br \/>$ReplaceText = \"spelled incorrectly\"<\/font><\/span><\/p><\/pre>\n<p>The remaining section of code is setting the replacement options: <\/p>\n<p><span>$ReplaceAll = 2<br \/>$FindContinue = 1<br \/>$MatchCase = $False<br \/>$MatchWholeWord = $True<br \/>$MatchWildcards = $False<br \/>$MatchSoundsLike = $False<br \/>$MatchAllWordForms = $False<br \/>$Forward = $True<br \/>$Wrap = $FindContinue<br \/>$Format = $False<\/p>\n<p><\/span><\/p>\n<p>The parameters of the <b>Execute<\/b> method from the <b>Find<\/b> object are documented in Table 1.<\/p>\n<table id=\"EFH\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead>\n<tr>\n<td class=\"tableHeader\" colSpan=\"4\">Table 1\u2003 Parameters of the Execute method of the Find object<\/td>\n<\/tr>\n<tr class=\"stdHeader\" vAlign=\"top\">\n<td id=\"colEIH\">Name<\/td>\n<td id=\"colEMH\">Required\/Optional<\/td>\n<td id=\"colEQH\">DataType<\/td>\n<td id=\"colEUH\">Description<\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">FindText<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">The text to be searched for. Use an empty string (&#8220;&#8221;) to search for formatting only. You can search for special characters by specifying appropriate character codes. For example, &#8220;^p&#8221; corresponds to a paragraph mark and &#8220;^t&#8221; corresponds to a tab character.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">MatchCase<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True to specify that the find text be case-sensitive. Corresponds to the <b>Match case<\/b> check box in the <b>Find and Replace<\/b> dialog box (Edit menu).<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">MatchWholeWorld<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True to have the find operation locate only whole words, not text that is part of a larger word. Corresponds to the <b>Find whole words<\/b> only check box in the <b>Find and Replace<\/b> dialog box.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">MatchWildcards<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True to have the Find text be a special search operator. Corresponds to the <b>Use wildcard characters<\/b> check box in the <b>Find and Replace<\/b> dialog box.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">MatchSoundsLike<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True to have the Find operation locate words that sound similar to the Find text. Corresponds to the <b>Sounds like<\/b> check box in the <b>Find and Replace<\/b> dialog box.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">MatchAllWordForms<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True to have the Find operation locate all forms of the find text (for example, &#8220;sit&#8221; locates &#8220;sitting&#8221; and &#8220;sat&#8221;). Corresponds to the <b>Find all word forms<\/b> check box in the <b>Find and Replace<\/b> dialog box.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">Forward<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True to search forward (toward the end of the document).<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">Wrap<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Controls what happens if the search begins at a point other than the beginning of the document and the end of the document is reached (or vice versa if <b>Forward<\/b> is set to False). This argument also controls what happens if there is a selection or range and the search text is not found in the selection or range. Can be one of the <b>WdFindWrap<\/b> constants.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">Format<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True to have the Find operation locate formatting in addition to, or instead of, the Find text.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">ReplaceWith<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">The replacement text. To delete the text specified by the Find argument, use an empty string (&#8220;&#8221;). You specify special characters and advanced search criteria just as you do for the Find argument. To specify a graphic object or other nontext item as the replacement, move the item to the Clipboard and specify &#8220;^c&#8221; for <b>ReplaceWith<\/b>.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">Replace<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Specifies how many replacements are to be made: one, all, or none. Can be any <b>WdReplace<\/b> constant.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">MatchKashida<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True if find operations match text with matching kashidas in an Arabic-language document. This argument may not be available to you, depending on the language support (U.S. English, for example) that you have selected or installed.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">MatchDiacritics<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True if Find operations match text with matching diacritics in a right-to-left language document. This argument may not be available to you, depending on the language support (U.S. English, for example) that you have selected or installed.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">MatchAlefHamza<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True if Find operations match text with matching alef hamzas in an Arabic-language document. This argument may not be available to you, depending on the language support (U.S. English, for example) that you have selected or installed.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">MatchControl<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True if Find operations match text with matching bidirectional control characters in a right-to-left language document. This argument may not be available to you, depending on the language support (U.S. English, for example) that you have selected or installed.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">MatchPrefix<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True to match words that begin with the search string. Corresponds to the <b>Match prefix<\/b> check box in the <b>Find and Replace<\/b> dialog box.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">MatchSuffix<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True to match words ending with the search string. Corresponds to the <b>Match suffix<\/b> check box in the <b>Find and Replace<\/b> dialog box.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">MatchPhrase<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True ignores all white space and control characters between words.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">IgnoreSpace<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True ignores all white space between words. Corresponds to the <b>Ignore white-space characters<\/b> check box in the <b>Find and Replace<\/b> dialog box.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">IgnorePunct<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Optional<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">Variant<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">True ignores all punctuation characters between words. Corresponds to the <b>Ignore punctuation<\/b> check box in the <b>Find and Replace<\/b> dialog box.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>The completed <b>ReplaceWordInWord.ps1<\/b> script is seen here.<\/p>\n<p><b>ReplaceWordInWord.ps1<\/b><\/p>\n<p class=\"CodeBlockScreened\"><font face=\"Lucida Sans Typewriter\">$objWord = New-Object -ComObject word.application<br \/>$objWord.Visible = $True<br \/>$objDoc = $objWord.Documents.Open(&#8220;C:\\fso\\test.doc&#8221;)<br \/>$objSelection = $objWord.Selection<\/p>\n<p>$FindText = &#8220;mispelled&#8221;<br \/>$ReplaceText = &#8220;spelled incorrectly&#8221;<\/p>\n<p>$ReplaceAll = 2<br \/>$FindContinue = 1<br \/>$MatchCase = $False<br \/>$MatchWholeWord = $True<br \/>$MatchWildcards = $False<br \/>$MatchSoundsLike = $False<br \/>$MatchAllWordForms = $False<br \/>$Forward = $True<br \/>$Wrap = $FindContinue<br \/>$Format = $False<\/p>\n<p>$objSelection.Find.Execute($FindText,$MatchCase,<br \/><span>&nbsp; <\/span>$MatchWholeWord,$MatchWildcards,$MatchSoundsLike,<br \/><span>&nbsp; <\/span>$MatchAllWordForms,$Forward,$Wrap,$Format,<br \/><span>&nbsp; <\/span>$ReplaceText,$ReplaceAll)<\/font><\/p>\n<p>As soon as the script is run, the corrected Word document is displayed:<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Image of the corrected Word document that is displayed\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/may\/hey0514\/hsg-05-14-09-03.jpg\" width=\"500\" height=\"375\" \/> <\/p>\n<p>&nbsp;<\/p>\n<p>Well, KL, we have got you up and running. If we were to modify the script, it would be to put it into a function to allow for us to more easily search for and replace multiple words. We would definitely move the hard-coded values, such as the path of the document and the search\/replace words, into parameters. It is becoming late, and I have to make my presentation tomorrow at Tech\u00b7Ed. It is in Room 152 at 2:45 P.M. If you are at Tech\u00b7Ed, stop by. It will be an awesome talk. Hope to see you then. Make sure that you join us for Quick-Hits Friday, when we will again open up the mail bag and grab those questions that can be answered in just a few paragraphs. See ya!<\/p>\n<p>&nbsp;<\/p>\n<p><b>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! The week of April 17, 2009, you did a weeklong series of \u201cHey, Scripting Guy!\u201d articles on regular expressions. I tried to change one of your scripts to open an office Word document that uses Windows PowerShell to look for a particular word. Guess what? It did not work. Instead, it filled [&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,4,5,155,45],"class_list":["post-53753","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-microsoft-word","tag-office","tag-scripting-guy","tag-scripting-techniques","tag-vbscript","tag-vbscript-migration","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! The week of April 17, 2009, you did a weeklong series of \u201cHey, Scripting Guy!\u201d articles on regular expressions. I tried to change one of your scripts to open an office Word document that uses Windows PowerShell to look for a particular word. Guess what? It did not work. Instead, it filled [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/53753","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=53753"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/53753\/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=53753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=53753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=53753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}