{"id":1789,"date":"2008-04-16T18:53:44","date_gmt":"2008-04-16T23:53:44","guid":{"rendered":"http:\/\/www.allyngibson.net\/?p=1789"},"modified":"2008-04-16T18:53:44","modified_gmt":"2008-04-16T23:53:44","slug":"on-writing-word-macros","status":"publish","type":"post","link":"http:\/\/www.allyngibson.com\/?p=1789","title":{"rendered":"On Writing Word Macros"},"content":{"rendered":"<p>Sometimes my Microsoft Word macro coding skills surprise even myself.<\/p>\n<p>Once a month, every month, I create about two dozen files.  Word documents, Excel spreadsheets &mdash; you name it, I&#8217;m creating it.  Fortunately, nothing in Powerpoint, because Powerpoint es el Diablo.<\/p>\n<p>Wait.  Why am I writing en espanol?  No habla espanol, por favor.<\/p>\n<p>This is your brain.  This is your brain after Word macro coding.  Any questions?<\/p>\n<p>One of the files I generated every month was a spreadsheet.  I&#8217;d perform some surgery on the spreadsheet, then import it into Word, and do some final clean-up and formatting.  All told, we&#8217;re talking fifteen minutes from spreadsheet generation to finished document.<\/p>\n<p>However.<\/p>\n<p>About four months ago that changed.<\/p>\n<p>The spreadsheet could still be generated out of the database.  Only, now there wasn&#8217;t any data on it.<\/p>\n<p>There had been a software update.  The database had changed.  There was a new field.  And things broke.<\/p>\n<p>Then the way that the information was being put into the database changed, and even if the procedure could be made to work again, it wouldn&#8217;t actually pull any data.<\/p>\n<p>Suffice it to say, I could still create the document.<\/p>\n<p>However, I had to create it by hand.  By going through another document I&#8217;d created &mdash; a 150-page Word document &mdash; and pulling the information out of that.  That takes about an hour and a half.  Compared to the fifteen minutes it had taken originally.  A six-fold increase in time, for no good reason.<\/p>\n<p>The information in that 150-page Word document is incredibly regimented.  Things go in a certain order, and they&#8217;re formatted in a certain way.<\/p>\n<p>What I realized, while on a walk on my lunch break, was that I could take that 150-page document, turn it into a table, chop the table, change it back into text, and delete a bunch of extraneous lines, and in so doing produce the document I got from the spreadsheet.<\/p>\n<p>It wouldn&#8217;t be exactly the <i>same<\/i> document.  In actuality, it would have a little <i>too<\/i> much information.  However, it would have all the information I needed, and then I could go through the resulting document by hand and delete what I didn&#8217;t need.<\/p>\n<p>The 150-page document would be chopped down into a specially-formatted 15-page document, and then I would cut that down to the 8-page document I needed.<\/p>\n<p>So I set to work coding.<\/p>\n<p>It took about three hours to write &mdash; and I still have the documentation inside the routine to write that explains what it does and why it does it &mdash; and it works.<\/p>\n<p>The first routine was <i>almost<\/i> perfect.  I made some code tweaks, and produced a macro that does precisely what I want, that takes the massive document and chops it into the much smaller document that I need.<\/p>\n<p>It&#8217;s not the speediest of macros.  It takes a good twenty minutes to run, but that&#8217;s the nature of the beast &mdash; Microsoft Word is good at many things, but it&#8217;s table functionality leaves much to be desired, <i>especially<\/i> on large tables.  Taking a 150-page document and turning it into an eleven column table takes <i>time<\/i>.<\/p>\n<p>There are some odds-and-ends to clean up with it tomorrow.  Besides the documentation, I want to encode what &#8220;Normal&#8221; should be into the macro, because the &#8220;Normal&#8221; used in the original document isn&#8217;t the &#8220;Normal&#8221; I want the final document in.<\/p>\n<p>Tomorrow, once I&#8217;m finished with the odds-and-ends, I&#8217;ll put it through a test run on last month&#8217;s files.  All told, I think it will take about half an hour &mdash; between running the macro and deleting the extraneous information &mdash; to create the document.  A far cry from the recent hour and a half it&#8217;s taken.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes my Microsoft Word macro coding skills surprise even myself. Once a month, every month, I create about two dozen files. Word documents, Excel spreadsheets &mdash; you name it, I&#8217;m creating it. Fortunately, nothing in Powerpoint, because Powerpoint es el Diablo. Wait. Why am I writing en espanol? No habla espanol, por favor. This is<a class=\"more-link\" href=\"http:\/\/www.allyngibson.com\/?p=1789\">Continue reading <span class=\"screen-reader-text\">&#8220;On Writing Word Macros&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[229],"tags":[426,4124],"class_list":["post-1789","post","type-post","status-publish","format-standard","hentry","category-work","tag-microsoft-word","tag-work","entry"],"_links":{"self":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/posts\/1789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1789"}],"version-history":[{"count":0,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/posts\/1789\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1789"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}