Macro-based HTML Tag Support for Microsoft Word
Many people reading this are lone bloggers or - as I like to call them - "armies of one." You manage the server, design the site, code the template, write posts, network with other bloggers, and market the blog. If you're like me, grammar is kind of on the backburner. Since, I can't really afford the price of hiring a full-fledged editor/proofreader or the time required to reread my articles an indefinite number of times, my dependence on the grammar check function is a bit more than recommended by most college professors.

The Problem with Plain Copy & Paste
Microsoft Office Word
In a perfect world, Microsoft and the makers of Wordpress would collaborate and somehow incorporate the grammar check into the "Write Post" console. Some may point out that the newest version of Microsoft Office now includes a "Publish -> Blog" function. However, this function doesn't allow bloggers to set nit-picky specific options like custom fields and trackbacks. Plus, not everybody has the $300+ to buy a copy of Microsoft Office 2007 or the expertise (or lack of morality) to install a cracked copy.
Macro Scripting
Since the current offering is pretty inadequate, why not write an alternative? The great thing about being a hacker is that you can roughly program in any language other than your "native tongue." I brushed up on my BASIC and wrote a VBScript macro for Microsoft Word. Basically, it brings the basic HTML Wordpress editor functionality to Microsoft Word. What's great is that the HTML tags generally do not interfere with the grammar/spell check function.

There are two functions in this script:
- Surround Selected Text with HTML Tags – To bold text for emphasis, highlight the text, run the macro, and specify the "strong" tag.
- Create Empty HTML Tags – To insert an image, run the macro, specify the "img " tag, enter the SRC URL, and enter the alt text.
Adding a Macro to Office
The actual process of adding this macro to Microsoft Office varies from version to version. But most roughly follow the same guidelines.
- Click "Tools," then "Macro," then "Visual Basic Editor."
- Paste the following code to the blank text area or after the last "End Sub" if there already is a macro in the Normal.dot template (probably not).
CODE:
-
Sub TagIt()
-
Dim URL As String
-
Dim Alt As String
-
Dim Tag As String
-
Dim OTag As String
-
Dim CTag As String
-
-
Tag = InputBox("Please enter the tag you want to use." & vbCr & vbCr & "Example: 'a' for ""<a></a>"" or ""strong"" for ""<strong>""")
-
-
If Tag = "" Then
-
End
-
End If
-
-
If Tag = "img" Then
-
URL = InputBox("What is the SRC URL for this <img> Tag?")
-
Alt = InputBox("What is the alt text for this <img> Tag?")
-
Selection.Text = "<img src=""" & URL & """ alt=""" & Alt & """ />" & Selection.Text
-
End
-
End If
-
-
If Tag = "a" Then
-
URL = InputBox("What is the URL for this <a> Tag?")
-
OTag = "<a href=""" & URL & """>"
-
CTag = "</a>"
-
-
Else
-
OTag = "<" & Tag & ">"
-
CTag = "</" & Tag & ">"
-
End If
-
-
Selection.Text = OTag & Selection.Text & CTag
-
End Sub
-
Click the save icon and close the window.- You may want to map this macro to a keystroke. I mapped it to "CTRL+T" since I hardly ever create a hanging indentations. It makes adding an HTML tag as seamless as bolding (CTRL+B) or cutting (CTRL+X) highlighted text.
-
- Right click on the Microsoft Word menu bar.
- Select "Customize…"
- Click the "Keyboard…" button.
- Scroll down to "Macros" and select "TagIt."
- In the "Press new shortcut key" dialog, type "CTRL+T." (Don't type "CTRL." Instead, hit the CTRL button on the keyboard.)
- Click "Assign."
Other Important Points
For those porting to OpenOffice and other office suite variants, the macro programming is similar. Most, if not all, macros are written in a flavor of BASIC. You'll probably just have to tweak the code a bit to match the host office suite's document object model (DOM).
Really, the number of supported HTML tags in this script is endless. If the elements include opening and closing tags, chances are that they're supported. For more complex elements like "<content>," you're on your own.
If you're really driven, why not take a stab at it and modify my script to include that tag?
Shoot a comment on your experience with my macro!
Update: If you would rather have a specific keystroke (or macro) for one tag, I found a post from another blog that shows you how to do that.

Subscribe by RSS Feed
Stumble it!
Furl This!
Reddit!
October 29th, 2008 at 2:10 pm
I found this post since it links to mine. I used to use Word 2007 a lot for posting to my blog. But that was till I discovered LiveWriter. You may be interested in this: http://blog.gadodia.net/using-windows-livewriter-to-publish-blog-posts/
Also, I used to have a problem with it till I realized at a much later date that it also has spellcheck: http://blog.gadodia.net/windows-live-writer-spell-check/
LiveWriter is a great replacement for Word 2007. Also, if you don't like either of these, just use FireFox or Chrome to type your posts directly into WordPress because both of them provide spell check right in the browser.
Cheers and thanks for linking to my post.