Effacer les filtres
Effacer les filtres

How can I set the MoveDown method to move down Paragraphs/Headings?

11 vues (au cours des 30 derniers jours)
Ivan
Ivan le 5 Déc 2014
Commenté : Ivan le 5 Déc 2014
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?
  1 commentaire
Ivan
Ivan le 5 Déc 2014
Also if I use NET.addAssembly it is working, but i have to stay with actxserver.
NET.addAssembly('microsoft.office.interop.word');
word = Microsoft.Office.Interop.Word.ApplicationClass;
document = word.Documents.Open([pwd '\Report_Generation\name_of_report.docx']);
word.Visible = true;
selection = word.Selection;
selection.MoveDown(Microsoft.Office.Interop.Word.WdUnits.wdParagraph, 1, Microsoft.Office.Interop.Word.WdMovementType.wdMove);

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 5 Déc 2014
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);

Plus de réponses (0)

Catégories

En savoir plus sur Use COM Objects in MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by