viSci Posted January 7, 2019 Report Share Posted January 7, 2019 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? Quote Link to comment
smithd Posted January 8, 2019 Report Share Posted January 8, 2019 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. Quote Link to comment
viSci Posted January 9, 2019 Author Report Share Posted January 9, 2019 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.