{"id":4586,"date":"2014-11-12T04:00:36","date_gmt":"2014-11-12T09:00:36","guid":{"rendered":"http:\/\/americaneditor.wordpress.com\/?p=4586"},"modified":"2016-09-16T11:46:57","modified_gmt":"2016-09-16T17:46:57","slug":"lyonizing-word-formatting-with-macros-2","status":"publish","type":"post","link":"https:\/\/editorium.com\/archive\/lyonizing-word-formatting-with-macros-2\/","title":{"rendered":"Lyonizing Word: Formatting with Macros"},"content":{"rendered":"<h3 style=\"text-align:center;\">Formatting with Macros<\/h3>\n<p style=\"text-align:center;\"><em><strong>by Jack Lyon<\/strong><\/em><\/p>\n<p>Most users of Microsoft Word format text by selecting a paragraph and then applying a font. More advanced users apply a style. Here\u2019s why:<\/p>\n<ol>\n<li>Styles are easier to use than direct formatting. Once you have the style set up (with, say, 12-point Arial bold, condensed by 1 point, left justified, with 24 points of leading above and 12 points of leading below), you can apply that style with a single click. But if you apply the same formatting <em>without <\/em>using a style, you\u2019ll have to make a dozen clicks for each heading. If your document has 50 headings, that\u2019s hundreds of clicks\u2014versus 50 clicks if you use a style.<\/li>\n<li>If you need to change the formatting of, say, level-2 headings, you can simply modify the style rather than tediously selecting each heading and applying a different font. Modify the style, and the formatting of all those headings is <em>automatically <\/em>changed.<\/li>\n<\/ol>\n<p>But there is a way to handle formatting that is even more powerful\u2014by using macros.<\/p>\n<p>Suppose that you\u2019ve dutifully applied styles to the various parts of a document, but then your client asks you to change the font\u2014everywhere in the document\u2014from Times New Roman to Adobe Garamond. (No, you should <em>not <\/em>just select the whole document and apply Adobe Garamond. Why? Because that simply \u201cpaints over\u201d the <em>real<\/em> formatting that is still there in the styles, and it will almost certainly lead to inconsistent formatting somewhere down the line.) You could manually modify each style, but if there are dozens of styles in use, there is a better way. That way is a macro, like this one:<\/p>\n<p style=\"padding-left:30px;\">Sub SetFontInAllStyles()<br \/>\nDim aStyle As Style<br \/>\nFor Each aStyle In ActiveDocument.Style<br \/>\naStyle.Font.Name = \"Adobe Garamond\"<br \/>\nNext<br \/>\nEnd Sub<\/p>\n<p>Well, that was easy. Let\u2019s look at each line of the macro (excluding the first and last lines, which simply define the beginning and end of the macro).<\/p>\n<p style=\"padding-left:30px;\">Dim aStyle As Style<\/p>\n<p>This line defines (dimensions) a variable, aStyle (which name I just made up), as a style. At one point as the macro runs, aStyle might represent the style Heading 1. At another point it might represent Heading 3. But it will always represent a style.<\/p>\n<p style=\"padding-left:30px;\">For Each aStyle In ActiveDocument.Styles<\/p>\n<p>Here's where things start to get interesting. That line tells the macro to cycle through each style (represented by aStyle) in all of the styles in the active document (the document in which your cursor is currently sitting).<\/p>\n<p style=\"padding-left:30px;\">aStyle.Font.Name = \"Adobe Garamond\"<\/p>\n<p>And that line tells Word to set the font for the style currently being represented by aStyle to be Adobe Garamond.<\/p>\n<p style=\"padding-left:30px;\">Next<\/p>\n<p>The \u201cNext\u201d line tells Word to go to the next style in the document.<\/p>\n<p>When you run the macro, it will cycle through each style in the document (For Each\u2026) and set Adobe Garamond as the font used in that style.<\/p>\n<p>But what if you want to change the font only in heading styles (Heading 1, Heading 2, and so on)? Try this:<\/p>\n<p style=\"padding-left:30px;\">Dim aStyle As Style<br \/>\nFor Each aStyle In ActiveDocument.Styles<br \/>\nIf InStr(aStyle.NameLocal, \"Heading\") Then aStyle.Font.Name = \"Adobe Garamond\"<br \/>\nNext<br \/>\nEnd Sub<\/p>\n<p>Here's the line of interest:<\/p>\n<p style=\"padding-left:30px;\">If InStr(aStyle.NameLocal, \"Heading\") Then aStyle.Font.Name = \"Adobe Garamond\"<\/p>\n<p>That line uses a macro command we haven't seen before, InStr, which checks for specific text in a larger string of text. In this case, it checks to see if the text \u201cHeading\u201d appears in the name of the style (for example, \u201cHeading 4\u201d). If it does, then the macro sets the font for the Heading style as Adobe Garamond.<\/p>\n<p>Armed with that little beauty, you can pull off all kinds of formatting marvels. Here are just a few of the options available:<\/p>\n<p style=\"padding-left:30px;\">If InStr(aStyle.NameLocal, \"Heading\") Then aStyle.Font.Bold = True<\/p>\n<p style=\"padding-left:30px;\">If InStr(aStyle.NameLocal, \"Heading\") Then aStyle.ParagraphFormat.Alignment = wdAlignParagraphCenter<\/p>\n<p style=\"padding-left:30px;\">If InStr(aStyle.NameLocal, \"Heading\") Then aStyle.NoSpaceBetweenParagraphsOfSameStyle = True<\/p>\n<p>You can even specify the exact name of the style (rather than using InStr):<\/p>\n<p style=\"padding-left:30px;\">If aStyle.NameLocal = \"Normal\" Then aStyle.ParagraphFormat.Alignment = wdAlignParagraphJustify<\/p>\n<p style=\"padding-left:30px;\">If aStyle.NameLocal = \"Heading 3\" Then aStyle.Font.Italic = True<\/p>\n<p>All of Word\u2019s formatting options are at your disposal.<\/p>\n<p>So yes, if you\u2019re formatting a Word document, you should always use styles. But if you need to modify styles <em>en masse, <\/em>now you know how.<\/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 \u201c______________.\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 ___________________.<\/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-formatting-with-macros-2\/\" rel=\"bookmark\" title=\"Permalink to Lyonizing Word: Formatting with Macros\"><p>Formatting with Macros by Jack Lyon Most users of Microsoft Word format text by selecting a paragraph and then applying a font. More advanced users apply a style. Here\u2019s why: Styles are easier to use than direct formatting. Once you have the style set up (with, say, 12-point Arial bold, condensed by 1 point, left [&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":[256,175,409],"tags":[767,769,770,267,446,771,772],"class_list":{"0":"post-4586","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-contributor-article","7":"category-editing-tools-editorial-matters","8":"category-lyonizing-word","9":"tag-contributor-article-2","10":"tag-formatting-macros","11":"tag-formatting-using-styles","12":"tag-jack-lyon","13":"tag-macros","14":"tag-ms-word","15":"tag-styles","16":"h-entry","17":"hentry"},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3gfno-1bY","_links":{"self":[{"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/posts\/4586","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=4586"}],"version-history":[{"count":1,"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/posts\/4586\/revisions"}],"predecessor-version":[{"id":6062,"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/posts\/4586\/revisions\/6062"}],"wp:attachment":[{"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/media?parent=4586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/categories?post=4586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/editorium.com\/archive\/wp-json\/wp\/v2\/tags?post=4586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}