{"id":4630,"date":"2014-12-29T04:00:00","date_gmt":"2014-12-29T09:00:00","guid":{"rendered":"https:\/\/americaneditor.wordpress.com\/?p=4630"},"modified":"2016-09-19T19:10:28","modified_gmt":"2016-09-20T01:10:28","slug":"lyonizing-word-finding-and-replacing-upper-and-lowercase","status":"publish","type":"post","link":"https:\/\/editorium.com\/archive\/lyonizing-word-finding-and-replacing-upper-and-lowercase\/","title":{"rendered":"Lyonizing Word: Finding and Replacing Upper- and Lowercase"},"content":{"rendered":"<h3 style=\"text-align:center;padding-left:60px;\">Finding and Replacing Upper- and Lowercase<\/h3>\n<p style=\"text-align:center;\"><em><strong>by Jack Lyon<\/strong><\/em><\/p>\n<p>Rich Adin, the proprietor of this blog, recently sent me an interesting question. He wrote:<\/p>\n<blockquote><p>I need a wildcard find and replace, assuming it can be done by wildcards, that searches for the following<\/p>\n<p style=\"padding-left:30px;\">Abrams: alpha<br \/>\nbooby: alarm<\/p>\n<p>and replaces it with<\/p>\n<p style=\"padding-left:30px;\">Abrams: Alpha<br \/>\nbooby: Alarm<\/p>\n<p>That is, the first letter after the colon and space is changed from lowercase to uppercase. I know I can do this by macro, and I have one that will do it, but I would like to do it by wildcard so I can make it part of a script I run.<\/p><\/blockquote>\n<p>Unfortunately, there's no good way to do that. Using a wildcard search, we can find any lowercase letter (preceded by a colon and space) by using the following string in the Find What box:<\/p>\n<p style=\"padding-left:30px;\">: [a-z]<\/p>\n<p>But in the Replace With box, we should use\u2014what? We can't use the following string because it doesn't specify what the replacement letter should be:<\/p>\n<p style=\"padding-left:30px;\">: [A-Z]<\/p>\n<p>In fact, if we try that, Word will simply replace what was found with the string itself, giving us this:<\/p>\n<p style=\"padding-left:30px;\">Abrams: [A-Z]lpha<br \/>\nbooby: [A-Z]larm<\/p>\n<p>There is, however, a rather sneaky (but ultimately unsatisfactory) workaround. We can replace the lowercase letter with itself <em>formatted as uppercase.<\/em> Here's how:<\/p>\n<p style=\"padding-left:30px;\">1. Press CTRL + H to bring up Word's Replace dialog.<br \/>\n2. If the More button is available, click it.<br \/>\n3. Put a check in the box labeled \"Use Wildcards.\"<br \/>\n4. In the Find What box, enter this:<\/p>\n<p style=\"padding-left:60px;\">: [a-z]<\/p>\n<p style=\"padding-left:30px;\">5. In the Replace With box, enter this<\/p>\n<p style=\"padding-left:60px;\">^&amp;<\/p>\n<p>That's the magic code that tells Word to replace what was found with what was found. In other words, if Word finds \": a\" it should replace it with \": a\" (the same thing it was searching for). You'll see why in just a minute.<\/p>\n<p style=\"padding-left:30px;\">6. Make sure your cursor is in the Replace With box.<br \/>\n7. Click the Format button at the bottom left of the Replace dialog.<br \/>\n8. Click Font.<br \/>\n9. Put a check in the box labeled \"All caps.\"<br \/>\n10. Click OK.<br \/>\n11. Click \"Replace All.\"<\/p>\n<p>That should do the trick; all of our lowercase letters following a colon and space are now formatted as \"All caps.\" The reason I said earlier that this is \"ultimately unsatisfactory\" is that those letters are not actually uppercase; they merely <em>look<\/em> as if they're uppercase because of their formatting.<\/p>\n<p>In some situations, that may be good enough. But if your document is destined to be published in a format other than Microsoft Word, it may <em>not<\/em> be good enough, as formatting may change and, like Cinderella at the stroke of midnight, our \"uppercase\" letters may revert to their true lowercase selves. (How often do we get to use a fairytale allusion in technical writing?)<\/p>\n<p>The only real solution is to use a macro, like this one:<\/p>\n<p style=\"padding-left:30px;\">Sub ReplaceLowercaseWithCaps()<br \/>\nSelection.HomeKey Unit:=wdStory 'Position cursor at top of document<br \/>\nSelection.Find.ClearFormatting 'Clear any<br \/>\nSelection.Find.Replacement.ClearFormatting<br \/>\nWith Selection.Find<\/p>\n<p style=\"padding-left:60px;\">.Text = \": [a-z]\" 'Search for colon and space followed by lowercase letter<br \/>\n.Replacement.Text = \"\" 'Leave empty--the macro will replace the text later<br \/>\n.Forward = True<br \/>\n.Wrap = wdFindStop<br \/>\n.Format = False<br \/>\n.MatchCase = False<br \/>\n.MatchWholeWord = False<br \/>\n.MatchAllWordForms = False<br \/>\n.MatchSoundsLike = False<br \/>\n.MatchWildcards = True 'Specify a wildcard search<\/p>\n<p style=\"padding-left:30px;\">End With<br \/>\nSelection.Find.Execute 'Execute the search<br \/>\nWhile Selection.Find.Found 'While the search is successful<\/p>\n<p style=\"padding-left:60px;\">Selection = UCase(Selection) 'Uppercase what was found<br \/>\nSelection.MoveRight 'Move out of the selection<br \/>\nSelection.Find.Execute 'Try, try again<\/p>\n<p style=\"padding-left:30px;\">Wend 'End the \"While\" loop<br \/>\nEnd Sub<\/p>\n<p>I've added comments to explain what's going on, but the really pertinent line is this one:<\/p>\n<blockquote><p>Selection = UCase(Selection) 'Uppercase what was found<\/p><\/blockquote>\n<p>When Word finds a colon and space followed by a lowercase letter, it selects the colon, space, and letter (naturally, because it found them), so those are the \"Selection.\" The macro then converts those characters to uppercase using the \"UCase\" function; it sets the Selection as the uppercased version of the Selection, if you see what I mean.<\/p>\n<p>After that, the macro moves to the right so the text is no longer selected. Then it again executes the Find in an effort to locate the next instance of colon, space, and lowercase letter, if one exists.<\/p>\n<p>And yes, for the sake of simplicity, the colon and space are uppercased here as well as the letter. What's an uppercased colon? A colon. What's an uppercased space? A space. If we wanted to, we could modify the macro to handle each of those separately, but why bother when the result is the same? Virtue in simplicity.<\/p>\n<p>Note that we could do the inverse of this, if we needed to, finding any uppercase letter and lowercasing it. To do so, we'd use \": [A-Z]\" for the search string, and we'd modify Selection with the LCase function rather than UCase.<\/p>\n<p>I wish that Microsoft had included a better way to handle this. Even though\u00a0Microsoft didn't, we now have a way to accomplish what we need to do.<\/p>\n<p><em>Jack Lyon (<\/em><a href=\"mailto:editor@editorium.com\"><em>editor@editorium.com<\/em><\/a><em>)\u00a0owns and operates the <\/em><a title=\"The Editorium\" href=\"http:\/\/www.editorium.com\" target=\"_blank\"><em>Editorium<\/em><\/a><em>, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of <\/em><a title=\"Microsoft Word for Publishing Professionals\" href=\"http:\/\/www.editorium.com\/msword4pubpros.htm\" target=\"_blank\">Microsoft Word for Publishing Professionals<\/a> <em>and of <\/em><a title=\"Macro Cookbook at Barnes &amp; Noble\" href=\"http:\/\/www.barnesandnoble.com\/w\/macro-cookbook-for-microsoft-word-jack-m-lyon\/1107868228?ean=9781434103321\" target=\"_blank\">Macro Cookbook for Microsoft Word<\/a>.<em> Both books will help you learn more about macros and how to use them.<\/em><\/p>\n<p>________<\/p>\n<h4>How to Add Macro to Word &amp; to the QAT<\/h4>\n<p>Here\u2019s how to put this macro (or any other) into Microsoft Word so it will be available when you need it:<\/p>\n<ol>\n<li>Copy the text of the macro, starting with the first \u201cSub\u201d and ending with the last \u201cSub.\u201d<\/li>\n<li>Click the \u201cView\u201d tab on Microsoft Word\u2019s ribbon.<\/li>\n<li>Click the \u201cMacros\u201d button.<\/li>\n<li>Type a name for the macro in the \u201cMacro name\u201d box \u2014 probably the name used after the first \u201cSub.\u201d For this macro, that\u2019s \u201cReplaceLowercaseWithCaps.\u201d<\/li>\n<li>Click the \u201cCreate\u201d button.<\/li>\n<li>Delete the \u201cSub [macro name]\u201d and \u201cEnd Sub\u201d lines that Word created in the macro window. The macro window should now be completely empty (unless you already have other macros in there).<\/li>\n<li>Paste the macro text at the current insertion point.<\/li>\n<li>Click \u201cFile,\u201d then \u201cClose and Return to Microsoft Word.\u201d<\/li>\n<\/ol>\n<p>To actually use the macro:<\/p>\n<ol>\n<li>Place your cursor at the beginning of your document.<\/li>\n<li>Click the \u201cView\u201d tab on Microsoft Word\u2019s ribbon.<\/li>\n<li>Click the \u201cMacros\u201d button.<\/li>\n<li>Click the name of your macro to select it.<\/li>\n<li>Click the \u201cRun\u201d button. (If you wanted to delete the macro, you could press the \u201cDelete\u201d button instead.)<\/li>\n<\/ol>\n<p>Here\u2019s how to put the macro on Word\u2019s QAT (Quick Access Toolbar):<\/p>\n<ol>\n<li>Locate the QAT (it\u2019s probably on the top left of your screen either above or below Word\u2019s Ribbon interface).<\/li>\n<li>Right-click the QAT.<\/li>\n<li>Click \u201cCustomize Quick Access Toolbar.\u201d<\/li>\n<li>Under \u201cChoose commands from:\u201d click the dropdown list and select \u201cMacros.\u201d<\/li>\n<li>Find and select your macro in the list on the left.<\/li>\n<li>Click the \u201cAdd\u201d button to add it to the QAT.<\/li>\n<li>Click the \u201cOK\u201d button to finish.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<a href=\"https:\/\/editorium.com\/archive\/lyonizing-word-finding-and-replacing-upper-and-lowercase\/\" rel=\"bookmark\" title=\"Permalink to Lyonizing Word: Finding and Replacing Upper- and Lowercase\"><p>Finding and Replacing Upper- and Lowercase by Jack Lyon Rich Adin, the proprietor of this blog, recently sent me an interesting question. He wrote: I need a wildcard find and replace, assuming it can be done by wildcards, that searches for the following Abrams: alpha booby: alarm and replaces it with Abrams: Alpha booby: Alarm [&hellip;]<\/p>\n<\/a>","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[77,256,22,409],"tags":[267,808,809],"class_list":{"0":"post-4630","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-computers-and-software","7":"category-contributor-article","8":"category-editorial-matters","9":"category-lyonizing-word","10":"tag-jack-lyon","11":"tag-macro-to-change-case","12":"tag-wildcards-vs-macros","13":"h-entry","14":"hentry"},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3gfno-1cG","_links":{"self":[{"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/posts\/4630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/comments?post=4630"}],"version-history":[{"count":1,"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/posts\/4630\/revisions"}],"predecessor-version":[{"id":6074,"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/posts\/4630\/revisions\/6074"}],"wp:attachment":[{"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/media?parent=4630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/categories?post=4630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/tags?post=4630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}