{"id":1186,"date":"2007-06-20T08:00:24","date_gmt":"2007-06-20T12:00:24","guid":{"rendered":"http:\/\/www.allyngibson.net\/?p=1186"},"modified":"2007-06-20T08:00:24","modified_gmt":"2007-06-20T12:00:24","slug":"on-word-macros","status":"publish","type":"post","link":"http:\/\/www.allyngibson.com\/?p=1186","title":{"rendered":"On Word Macros"},"content":{"rendered":"<p>I&#8217;ve written my first Microsoft Word macro since, let me think, 1999.  I&#8217;ve recorded macros to do repetitive tasks, but for work I needed something a little more&#8230; robust.  Yeah, robust.  That&#8217;s a good word.  Robust.<\/p>\n<p>Wait.  What was I saying?  Oh, yes.<\/p>\n<p>There&#8217;s a process I have to run once a month.  I ran it, the first time, my second day on the job, and I had a feeling that the macro the company supplied to do the job didn&#8217;t do the job when I ran it.  When the printouts came, I knew&#8211;the macro <i>hadn&#8217;t<\/i> worked.  When I ran the process again last week, again, I felt that the macro hadn&#8217;t worked, though I managed to manually fix ninety percent of what the macro was supposed to catch.<\/p>\n<p>I had some downtime this morning while waiting on a report, so I decided to look at the macro code.<\/p>\n<p>If my jaw could have hit my desk, my jaw would have hit the desk.<\/p>\n<p>First, I hadn&#8217;t seen a macro written in WordBasic in, oh, ten years.  WordBasic went out of style when Office 97 came out.<\/p>\n<p>Second, the reason the macro didn&#8217;t work was because what the macro was <i>supposed<\/i> to do the macro wasn&#8217;t <i>coded<\/i> to do.<\/p>\n<p>I talked to my supervisor, explained what I wanted to do, drew lots of circles as a demonstration, and he told me to knock myself out.<\/p>\n<p>I think I spent four hours on thirty lines of code.  I wrote out the algorithm in plain English, then started looking for VBA examples online and in the VBA help system.  (I have a VBA manual, but it&#8217;s in storage.  Fat lot of good it&#8217;s doing me there.)  And I used the macro recorder for the one tricky text manipulation I needed done.  I found an example of the Do&#8230; Loop structure I wanted.  I consulted VBA&#8217;s WordBasic-to-VBA equivalent page.  I plugged in the code I&#8217;d recorded.  Two other functions I&#8217;d done manually with the same data the original macro dealt with I automated with two more lines of code.  I was shocked&#8211;it worked right the first time.<\/p>\n<p>If I have more time this week there are more functions I&#8217;ll add.<\/p>\n<p>The process will <i>never<\/i> reach the point where I&#8217;ll be able to press a single button and <i>voila!<\/i> because, let&#8217;s be frank, that would be obscene.  But a whole sequence of search-and-replaces can be automated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve written my first Microsoft Word macro since, let me think, 1999. I&#8217;ve recorded macros to do repetitive tasks, but for work I needed something a little more&#8230; robust. Yeah, robust. That&#8217;s a good word. Robust. Wait. What was I saying? Oh, yes. There&#8217;s a process I have to run once a month. I ran<a class=\"more-link\" href=\"http:\/\/www.allyngibson.com\/?p=1186\">Continue reading <span class=\"screen-reader-text\">&#8220;On 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":[339,426,4124],"class_list":["post-1186","post","type-post","status-publish","format-standard","hentry","category-work","tag-computers","tag-microsoft-word","tag-work","entry"],"_links":{"self":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/posts\/1186","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=1186"}],"version-history":[{"count":0,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=\/wp\/v2\/posts\/1186\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1186"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.allyngibson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}