Add a 3 column table to the bottom of a word document using c#

Posted on 2009-05-01
Last Modified: 2013-11-10
Hi Experts,

I'm attempting to create an ActionsPane in word that will allow users to add comments to a table at the bottom of the document, so that as they are reviewing the document, they can add an entry into the word table by entering the comments in the actionspane and hitting a button.

So how would I go about:
1.  Seeing if a table already exists (lets call it CommentTable); if it does move on to step 2, if not, add the table with 3 columns of 1"; 1",4.5" widths.
2.  Add a new line to the bottom of the table; there will be 3 fields called Section, Reviewer, Comment with data from the actionpane.

Thanks for the help!
Question by:deedub84
    LVL 4

    Accepted Solution

    Well, I don't have the time right now and I'm sure other experts might provide you with the needed code examples, but here's a tip on how to get the code yourself:

    Use Word macro recorder along with editing or tweaking the VB macro code in Word to do what you want. A trial & error test. Basically the VB macros along with the Word COM API will provide you all the needed methods and properties to add a new line or row to the table or to insert a table with the specified properties. Then once you have the macro code working like the way you kind of want it, you can port the VB code over to C#. Because I'm assuming you are using the Word COM/DLL library, the API calls will be the same, only the syntax is slightly different. There should be Word API reference available in the macro editor, and if not, then online.

    One note I'd like to mention though, using Word API in .NET/C#, your API support will be tied to the version of Word that is on your development environment that you will compile the code on. Therefore you might run into problems if your end user has a different version of Word installed. If you ever need broad Word version support, avoid using API calls that are specific to a Word version, or better yet, have the .NET/C# code call a VBScript that will interact with Word, where possible, since the VBScript COM interface is more version lenient than the .NET interface to Word is.
    LVL 1

    Author Comment

    Thanks for the tip daluu.  I'm just venturing into the c# world from the vba world and have zero 'court sense' as of yet.  I'll give your suggestions a whirl.


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    This is an explanation of a simple data model to help parse a JSON feed
    A short article about problems I had with the new location API and permissions in Marshmallow
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now