Jump to content
News about the LabVIEW Wiki! Read more... ×

Create table in active word document

Recommended Posts

I would like to obtain a .net reference to an open word document and add a table at the current cursor location in the document.  I can already do this using a crude

automated copy and paste method but would like to be able to add a proper word table into the document.  Using the .net interfaces I think this is possible but so far

have not been able to get it to work.  Has anyone tried to do this before? 

Share this post

Link to post
Share on other sites

I was under the impression that the .net interfaces just wrapped the old activex interfaces. Is that wrong?

to actually answer your question I've never used it, but it seems like these might work:

text ("TextType" section halfway down): https://docs.microsoft.com/en-us/visualstudio/vsto/how-to-programmatically-insert-text-into-word-documents?view=vs-2017

table: https://docs.microsoft.com/en-us/visualstudio/vsto/how-to-programmatically-create-word-tables?view=vs-2017

If I'm reading the samples right it looks like you can get the current cursor from "Application.Selection" and then insert a table using a method on that object.

Share this post

Link to post
Share on other sites

Thanks - I was able to use your suggestion to get the current cursor position and it worked correctly.  I was able to construct and insert a proper table in an open word document. 

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

By using this site, you agree to our Terms of Use.