New Photos:

  New Ramblings:

  New Links:


Last Updated


Previous Posts

About the Blog

The thoughts and theories of a guy who basically should have gone to bed hours ago.

I know, I know - what's the point? But look at it this way - I stayed up late writing it, but you're reading it...

Let's call ourselves even & move on, OK?

Powered by Blogger

Sunday, December 02, 2007

Excel Macro to Create Table HTML

Way back in August of 2006, I posted on how to make HTML tables appear properly in Blogger posts. Since then, whenever I needed one, I'd write out the code in a text editor, get it just like I wanted it, and remove all the line breaks and paste the resulting (cryptic) code in my post.

It occurred to me recently that Excel should be able to do this for me. I tried the "Save As HTML" feature, but the HTML code it generates is exceedingly difficult to read. It's not that it's incorrect, mind you, it's just that it includes individual style elements for each cell, so the resulting HTML is very flexible, but also very difficult to read.

To address this problem, I've written a quick Visual Basic macro that creates simple HTML code, like most people use for quick and dirty tables in blogposts.

Here's what you need to do:

1)Open Excel
2)Press Alt-F11 (or use menus: Tools...Macro...Visual Basic Editor)
3)Right Click on the current workbook (probably entitled "Book1") and choose Insert...Module
4)Cut and paste the text in the above file EXACTLY AS IS
5)Choose File...Save Book1, and then save it as a Microsoft Office Excel Add-In (with a .XLA extension)
6)Close the visual basic editor
7)Back in Excel, choose Tools...>Add Ins, and browse to the file you just saved. Make sure the check box next to it is checked.

Then, create your table in excel, highlight the entire thing, and run the macro (either using Tools...Macro...Macros, or by assigning it to a button or menuitem). The macro will recognize bold and italics in each cell, and will also ask you if you want to specify column widths. If you say yes, you'll be prompted for a column width for each column in the table.

You'll then get a Messagebox informing you that your HTML table code has been placed in the clipboard. Go to Blogger, and paste it in your post (the code has no linebreaks, so it will display properly in blogger).

If you want to edit the table, you can either fix it in Excel and re-run the Macro, or just edit the code directly. In the table above, for instance, I manually set the table border to zero, as opposed to the default value of one. I also added VALIGN=top to each cell so the list would look right.

Enjoy. If you have any questions, feel free to send me an e-mail at

posted by Brian at 12:01 PM


Post a Comment

<< Home