I
I
Ingvar Von Bjork2018-03-17 19:43:03
C++ / C#
Ingvar Von Bjork, 2018-03-17 19:43:03

How to find and change the table property in a Word document?

Actually there is a Word document in which some text and several tables are written. You need to change the styles of text and tables. And if by changing the text everything is clear and quite even turns out, then with tables it’s a complete zero.
I'm trying to get a table like this:

Word.Range rng = document.Paragraphs[1].Range;
Word.Table tbl = rng.Tables[1];

But it throws an error:
System.Runtime.InteropServices.COMException: "The requested family number does not exist."

Answer the question

In order to leave comments, you need to log in

2 answer(s)
#
#, 2018-03-17
@DeboshiR

advice - turn on macro recording, do manipulations with the table, the very ones that you want to automate, complete the recording, open VBA and transfer from VB to sharp, what will be in the recording
is a fairly universal recipe, when working with office
ps though the translation is not always absolutely obvious. but you can quickly get used to it

L
lvv85, 2018-03-17
@lvv85

Replace rng with document
Word.Table tbl = document.Tables[1];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question