My foray into macros - part 118/03/16
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.
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.
The process for uploading a web page was:
- Open up a template HTML file containing the header and footer and a framework
- Put in all the headings inside heading tags
- Copy and paste each paragraph in between paragraph tags
- Copy and paste each list bullet inside list tags
- Type the code for links
- Type the code for images
- 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.