knowledgeDoc

My foray into macros - part 1

Rachel Woolley
by Rachel Woolley

For a while I’ve considered myself a pretty good user of Microsoft products like Word and Excel, and I’ve always been figuring out new things to do with them. I’ve heard a lot about macros but they’ve always seemed to be a magical thing that was used to do very complicated things, but I wasn’t really sure what sort of things.

It was only when Rhonda Bracey mentioned macros at the ASTC conference in Melbourne in October 2015 that I thought about investigating them seriously. I’ve done a little bit of coding, starting with MATLAB at university and some online tutorials in the basics of web development, mostly HTML, CSS and JavaScript. So the prospect of teaching myself a new coding language was much less daunting than it would have been a few years ago.

My first problem was where to start? I decided that the easiest way for me to learn about macros would be to have a problem I wanted to solve and work out how to fix it. From what I learned about macros, their best use was for repetitive things. So I sat down to think about my most repetitive tasks.

A little bit of backstory, I redesigned our website not long after I started at Knowledgedoc. It started out as a self-teaching project to familiarise myself with HTML, CSS and JavaScript and then the company decided to implement the website. The downside of my website design was that because I wrote it from scratch in a text editor (and didn’t use a content management system), uploading new web pages was a bit time consuming. And I was uploading a blog article a week! My other concern was that other people at Knowledgedoc are not as familiar with HTML as I am and therefore would probably have difficulty uploading new pages.

The process for uploading a web page was:

  1. Open up a template HTML file containing the header and footer and a framework
  2. Put in all the headings inside heading tags
  3. Copy and paste each paragraph in between paragraph tags
  4. Copy and paste each list bullet inside list tags
  5. Type the code for links
  6. Type the code for images
  7. Put the URL of the page into the social media share buttons on the side of the page.

I was efficient enough at the process that I could convert a Word article into HTML in about 20 minutes as long as there weren't a lot of images. But this still seemed far too long to me. I looked into a few different options at the time – writing the articles in Adobe Dreamweaver, using the Word Save as HTML functionality, and migrating the website to a content management system, but none of these options were really viable.

This is exactly the type of project I wanted for my macro.

My initial plan was to set up a Word template with custom styles for everything. For example my paragraph style would be HTML Paragraph and my heading styles would be HTML Heading 1 and so on. My macro would then search for a particular style and for each paragraph insert the appropriate HTML tags around it.

The full list of things I wanted my macro to do was:

  • Put ‘p’ tags around paragraphs
  • Put ‘h’ tags around appropriate headings (For example h2 for heading 2 style)
  • In addition for heading 1:
    • Put <span id=”head”></span> around text
    • Copy text into the <title></title> at the top of the page
  • Put ‘ul’/’ol’ tags around lists
  • Put ‘li’ tags around list items, and remove the actual bullet
  • Put ‘strong’ tags around bold
  • Put ‘em’ tags around italic
  • Put links to other pages in
  • Put images in with a link to the source of the image and alternate text for the image
  • Put all head, navigation and footer information in
  • Put appropriate sections around headings/content as per HTML5 standards
  • In addition for blog articles:
    • For heading 1: put the publish date of the article in and put a span around the publish date
    • Put social media share buttons on the side of the page including the URL of the page
    • Insert image of author.

Not exactly a short list.

If you don't have any experience with HTML Mozilla has a good introduction to HTML that covers the basics so you can understand what I'm talking about. And if you want to look at the HTML of the web pages that I'm talking about most browsers have a function where you can right-click and select Inspect or Inspect Element to look at the HTML of a page.

Next week I'll talk about how I tackled the very ambitious macro project that I'd devised for myself.

Back to blog home.