Oct
27

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

I know many lone bloggers who write and format posts on Microsoft Word just for the spell/grammar check function. After they finish an article, they port the post to WordPress using copy/paste. However, with this method, the formatting gets either skewed in the visual WordPress Editor - since the original formatting is in Microsoft's rich text format - or lost in the plain-text HTML WordPress editor. Trust me, its not fun ALT+TAB alternating between Word and WordPress windows trying to synchronize the formatting. Because of this, I personally prefer to write my posts in raw HTML. I think it's a control issue. 🙂

 

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.

  1. Click "Tools," then "Macro," then "Visual Basic Editor."
  2. 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:

    1. Sub TagIt()
    2. Dim URL As String
    3. Dim Alt As String
    4. Dim Tag As String
    5. Dim OTag As String
    6. Dim CTag As String
    7.  
    8. Tag = InputBox("Please enter the tag you want to use." & vbCr & vbCr & "Example: 'a' for ""<a></a>"" or ""strong"" for ""<strong>""")
    9.  
    10. If Tag = "" Then
    11.     End
    12.     End If
    13.  
    14. If Tag = "img" Then
    15.     URL = InputBox("What is the SRC URL for this <img> Tag?")
    16.     Alt = InputBox("What is the alt text for this <img> Tag?")
    17.     Selection.Text = "<img src=""" & URL & """ alt=""" & Alt & """ />" & Selection.Text
    18.     End
    19.     End If
    20.  
    21. If Tag = "a" Then
    22.     URL = InputBox("What is the URL for this <a> Tag?")
    23.     OTag = "<a href=""" & URL & """>"
    24.     CTag = "</a>"
    25.  
    26. Else
    27.     OTag = "<" & Tag & ">"
    28.     CTag = "</" & Tag & ">"
    29.     End If
    30.  
    31. Selection.Text = OTag & Selection.Text & CTag
    32. End Sub
  3. Click the save icon and close the window.
  4. 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.
    1. Right click on the Microsoft Word menu bar.
    2. Select "Customize…"
    3. Click the "Keyboard…" button.
    4. Scroll down to "Macros" and select "TagIt."
    5. In the "Press new shortcut key" dialog, type "CTRL+T." (Don't type "CTRL." Instead, hit the CTRL button on the keyboard.)
    6. 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.

If you enjoyed this post, make sure you subscribe to hacker not cracker via RSS feed or email update!



Additional Reading

Comment View Comments from Other Readers

Popular Posts

Featured Posts

Related Posts

Recent Posts

What's Your Reaction?


Subscribe to this Blog:

Reader Reactions Elsewhere


 

15 Responses to “Macro-based HTML Tag Support for Microsoft Word”

  1. Vaibhav Says:

    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.

  2. killer Says:

    me want same pasword

  3. Marcello Says:

    AutoAP was updated.
    Can you update the guide?
    Thank you!

  4. Kenji Says:

    I have read a ton of posts on this and not one has explained how to get ports to work in XP... You can \

  5. John Burger Says:

    Thank you for the education on Port Forwarding...It is a great Public Service that you provide.

    If you accept donations for your work, let me know.

    Thank You

  6. blogger Says:

    Thank you for the kind words. I've added a link on the bottom of the sidebar appearing on all pages in my site. Click "Donate" and it will take you to PayPal.

    Allan

  7. anu Says:

    Thanks for this inforamtions. I am using the samsung mobile & it was locked i found the free code from http://www.unlock-free.com/ after unlock it i want to download the ringtones Thanks in advance.

  8. ben Says:

    i want to open my site as well as open ....whit fast vpv...needed

  9. Vishal Says:

    It\'s really the nicest answer i have found over the net.
    My pc is connected to a router through a hub and there are some other PCs in the network.
    I hav installed a CrossFTP server on my PC and created accounts and given those accounts access to some directories.
    I forwarded the port 21 by goin to routers configuration and saved it n rebooted the router.
    I went to other PC and typed 192.168.1.3:21 in the browser.
    I expected to get a login page so that i can type my username n passwod for the accounts i created in CrossFTP server, but it\'s not so.
    Would i have to open the port 21?
    I have forwarded the port 21....

    Plz help me out...

    Thanx...

  10. stan Says:

    Hi there,
    What if I\'m not using a router but going directly in with a cable modem? I\'m trying to set port forwarding so I can access it using Remote Desktop. All the instructions I see online assume I\'m using a wireless router, which I\'m not. Thanks!

  11. peg Says:

    What is the newer faster way for Vista. I bought an acer notebook and I believe this thing is locked somehow I cant uninstall anything and any administrator command just fades away to who knows where. I appreciate any light you can shed on thisThanks Peg

  12. omar Says:

    hi
    i have forgotten my password and i have lost my cd and the methods you have stated above do not work..........i have a old computer and it runs on windows 2000 profesional and i was hoping if you had a methgod on how to to reinstall it.

    help

  13. Tony54 Says:

    I tried to use this to fix a different problem and thought it would work but it didn't. I was trying to upload using uTorrent 1.8.4 but it wouldn't work unless ALL the file DIRs were set to the same DIR. In the process I accidentally deleted some of the .torrent files not the download file. Now uTorrent says cant open torrent file at L:\DL Torrents. I tried getting new torrent files from the same place & putting them in both L:\DL Completed (where everything is now) and L:\DL Torrents where they were originally but no hope. I tried your idea above thinking it would go to 100% when I restarted but it didn't work.
    Any ideas would be appreciated !!!!!!!!!!!!!

  14. free ps3 id Says:

    Hi there! This blog post could not be written much better!
    Going through this article reminds me of my previous roommate!
    He constantly kept preaching about this. I am going to send this post to him.
    Fairly certain he will have a great read. Thank you for sharing!

  15. ambrosebradeyyt5 Says:

    michael kors mens calendar year
    customize
    . Do this
    louis vuitton speedy pochette

    Lincoln Square. cet endroit est exceptionnel. ils ont des morceaux vraiment dramatique, robes incroyables pour le soir. la plume brassard.

    . You can aquire a assistance in the . In case you before the a genuine for almost all of any packed with gifts connected with an inexpensive discounts substantial overlooks need for . An execllent authentic pumps M94035 Louis Vuitton Mahina Leather Selene PM Black

    preferred to be considered , when the michael kors bridal. Every single details of . Or when , they will a good idea to excellent you are going to wish cheap Hermes Handbags since the Hermes high heels apparel the net expresses . However .As the . Additionally you can showing off are typical A high level louis vuitton belts online

 
© 2006 and web design of Allan Ray Barizo from [art] [⁄app].
This site is best viewed with FF and at least 1024x768 resolution.