How can I set landscape and margins in word using matlab activex
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am using writetoword.m from the matlab file exchange to print figures and text to a word document but I would also like to make the document landscape orientation and change the right and left margins to 1cm as well.
I tried adding these lines of code at the beginning of the wrtietoword.m file after it creates the word document:-
This line gives no errors but does not seem to do anything and does not change the orientation to lanscape:- actXword.ActiveDocument.Pagesetup.Orientation = 'wdOrientLandscape';
Thesee lines give an error actXword.ActiveDocument.Pagesetup.LeftMargin = 'CentimetersToPoints(1)'; actXword.ActiveDocument.Pagesetup.RightMargin = 'CentimetersToPoints(1)';
Can anyone hep with the right syntax. Is there a good guide anywhere for the matlab activex syntax versions of VBA commands ?
thanks Andrew
0 Commenti
Risposta accettata
Eric
il 1 Nov 2012
Modificato: Eric
il 1 Nov 2012
wdOrientLandscape is part of an enumeration. It's value is actually 1.
The proper usage for CentimetersToPoints should be
actXword.CentimetersToPoints(1)
but this gives an error. I'm not sure why. However, this is easy enough to set without calling the function as 1 cm is equal to 28.3464567 points.
I'm not sure of a good guide. The command structure for the COM interface to Word is quite similar to the VBA commands - you just have to be careful. Some thoughts that come to mind:
1. You can never assume that the root object is known. For example, in VBA you generally don't have to supply the base "Application" argument. This is why you would need to supply actXword.CentimetersToPoints rather than just CentimetersToPoints when calling the function from Matlab.
2. You have to be careful with collections and how you index into them. In VBA you can often supply a text argument to index into a collection (e.g., reference a worksheet by its name in Excel). This does not work in the COM interface. You have to index into the Item property of the collection.
3. You also have to be careful with enumerations (see above). To get enumeration values, open the VBA editor and go to the Immediate window. To get the value for an enumeration type
?enumerationName
This will show you the actual numerical value to use. You can also look these up on the web.
4. A useful function in Matlab is methodsview(). This can give you information about what methods an object supports.
Good luck,
Eric
0 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Use COM Objects in MATLAB in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!