A Word macro for creating a table in a post

Getting the most out of Eileen's Lounge!
User avatar
HansV
Administrator
Posts: 69487
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

A Word macro for creating a table in a post

Post by HansV »

Warning: this is a rather "technical" thread.

Producing the series of tags that result in a table within a post is very tedious: you have to create a tag pair for the table as a whole, a tag pair for each row in the table, and a tag pair for each cell within each row.

The macro Table2Lounge in the attached text file will convert a (simple) table in a Word document into the code needed for inclusion in a post.
You can copy the macro into a code module in Word; if you copy it into a module in your Normal template, it will be available in all posts.
To convert a table, click anywhere inside it, then run the macro (Alt+F8 displays the Macros dialog in all versions of Word).

Example:

Here is a screenshot of a table in a Word document:
x63.png
Clicking inside it (in Word) and running the Table2Lounge macro places the following code on the clipboard, ready to be pasted into a post:

[table=1][tr=bottom][td=left]Mary
had[/td][td=left]a[/td][td=center]little[/td][/tr][tr=middle][td=right]lamb[/td][td=left]and
its[/td][td=left]fleece[/td][/tr][/table]

When posted, this results in:
Mary
had
alittle
lamband
its
fleece
Note: to run the macro, you must have a reference to the Microsoft Forms 2.0 Object Library in the Visual Basic Editor. The easiest way to create the reference is to insert a userform (Insert | Userform). The userform can be kept or discarded, that doesn't matter.
TableMacro4Word.txt
Warning: if your table contains merged cells, you'll get an error message. The macro was not intended to handle merged cells, since the table tags in the Lounge don't support them.
You do not have the required permissions to view the files attached to this post.
Regards,
Hans