How to use MoveDown method to move down Tables?

3 views (last 30 days)
Hi,
I'm using the ActiveX server and I have to insert some *.PNG pictures in specific table/row locations in a Word Document. I've already tested several approaches and I am now trying to insert them by using the MoveDown method. However, I've tried to use the WdUnits given in:
https://www.mathworks.com/matlabcentral/answers/165541-how-can-i-set-the-movedown-method-to-move-down-paragraphs-headings
And it is not working. If I type in: selection.MoveDown(15,1,0);
To move down one table, MatLab gives this error:
Error using Interface.00020975_0000_0000_C000_000000000046/MoveDown Invoke Error, Dispatch Exception: Source: Microsoft Word Description: Bad parameter Help File: wdmain11.chm Help Context ID: 9018
But if I type in: selection.MoveDown(5,1,0);
To move down one paragraph, it works. But for what I’m doing it is not feasible at all. Can someone help me with this?
Thanks!

Accepted Answer

Guillaume
Guillaume on 17 May 2017
Edited: Guillaume on 17 May 2017
I suspect you get an error because moving down one table is not valid in the current selection context (is there more than one table?).
Unfortunately, I find manipulating word selection programatically infuriating as Microsoft documentation is severely lacking in details. You end up finding something that works by trial and error.
Is it really from table to table that you want to move, rather than table cell to table cell? If the latter, I'd get the table cell without involving selection and set the selection to the content of that cell:
word = actxserver('Word.Application');
selection = word.Selection; %acquire selection reference
%...
table = wdoc.Tables.Item(n); %where wdoc is your word document, and n the index of the table
table.Cell(row, column).Range.Select; %move selection to specific row and column of table
selection.TypeText('Hello world!') %do something with selection
If it's table to table, I'd still use the same principle (index the table collection, get selection from table object).
  3 Comments
Madalena Lacerda
Madalena Lacerda on 26 May 2017
And by the way, is it possible to add rows to a word table using the ActiveX server?
Thanks!
Guillaume
Guillaume on 27 May 2017
Of course, it's possible. Use the Add method of the Rows collection of your Table. e.g.:
newrow = table.Rows.Add; %add a row at the end
newrow = table.Rows.Add(table.Rows.Item(2)); %add a row before the 2nd row

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!