MATLAB: How to set the MoveDown method to move down Paragraphs/Headings

actxserver office word movedown wdparagraph

Hi, I'm using actxserver('Word.Application') to copy data from Matlab to a Word template. And I'm having problems with the navigation in the document.
%Initialization
word=actxserver('Word.Application');
document=word.Documents.Open([pwd '\Report_Generation\name_of_report.docx']);
word.Visible=1;
selection=word.Selection;
If I write
selection.MoveDown
or
invoke(selection,'MoveDown');
Then it's working, the selection moves down a line in the Word doc.
But if I would like the selection to move down paragraphs (or headings), not lines, and I set the arguments to wdParagraph I get an error. (even if i set the unit to wdLine, which is the default value).
>> selection.MoveDown(wdParagraph)
Undefined function or variable 'wdParagraph'.
>> selection.MoveDown(Microsoft.Office.Interop.Word.WdUnits.wdParagraph, 1, Microsoft.Office.Interop.Word.WdMovementType.wdMove)
Undefined variable "Microsoft" or function "Microsoft.Office.Interop.Word.WdUnits.wdParagraph".
>> invoke(selection,'MoveDown',wdParagraph);
Undefined function or variable 'wdParagraph'.
Do You know how to set properly the arguments of these methods?

Best Answer

Matlab is hopeless with COM enumerations, they don't get imported. As a result instead of using the enumaration names, you have to use the values.
Unfortunately, as well, MSDN is not very forthcoming on these values. I had to use Visual Studio object browser to get them. They are:
WdUnits.
wdCell = 12
wdCharacter = 1
wdCharacterFormatting = 13
wdColumn = 9
wdItem = 16
wdLine = 5
wdParagraph = 4
wdParagraphFormatting = 14
wdRow = 10
wdScreen = 7
wdSection = 8
wdSentence = 3
wdStory = 6
wdTable = 15
wdWindow = 11
wdWord = 2
WdMovementType.
wdExtend = 1
wWdMove = 0
Thus:
selection.MoveDown(4, 1, 0);