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 brian@familygreenberg.com.
posted by Brian at
12:01 PM
2 Comments:
I want to quote your post in my blog. It can?
And you et an account on Twitter?
By
Anonymous, at 4:14 AM, December 25, 2009
Feel free to quote all you like - just please link them back here if you don't mind.
By
Brian, at 11:00 AM, December 25, 2009
Post a Comment
<< Home