File Exchange

image thumbnail

ActiveX Word control base commands

version 1.21.0.0 (28.6 KB) by Stefan Braun
Base commands to control Word in Matlab

26 Downloads

Updated 21 Jul 2016

View License

This is an example to learn how to control Microsoft Word in Matlab.
(tested on Microsoft Office 2007)
This example contains:
-define Font
-define Font Size
-define Page setup
-write Text
-color background
-highlight text
-underline text
-change format of text
-insert figures from Matlab as picture in Word
-insert picture from file

Cite As

Stefan Braun (2020). ActiveX Word control base commands (https://www.mathworks.com/matlabcentral/fileexchange/56283-activex-word-control-base-commands), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (10)

Thanks for these examples !
Thanks to Charlie Levett for debugging.

fhz

Excellent!
With your code I finally learned how to align the text and how to paste a figure directly from matlab and from a folder.

I was having issues with the SaveAs function but found adding '2' after worked:

document.SaveAs2([pwd '/test.docx'])

Also the font color part didn't work for me but this did:

selection.Font.TextColor.RGB = 16777215

Thanks for these informations, nevertheless, I need to insert a equation in document (.docx). Do you Know How I make it? I was not successful to use a class OMaths.

It does not run and I get this error:

The 'Color' property name is ambiguous in the '00020952_0000_0000_C000_000000000046' class.

Error in Word_example (line 85)
selection.Font.Color=16777215;

I need to know how to format the page setup to "landscape" format - couldn`t find it in the examples and overview.

Can someone help?

THX

@Mark Breutzman perhaps this could help:

invoke(document,'saveas',docPath);

working here!

I'm trying to adapt this for my own purpose, but keep having problems with SaveAs:

Cannot find an exact (case-sensitive) match for 'SaveAs'

The closest match is: saveas in C:\Program Files\MATLAB\R2016b\toolbox\matlab\general\saveas.m

Error in Word_example (line 241)
document.SaveAs([pwd '/test.doc']); %save Document

What am I missing?

John

Updates

1.21.0.0

-

1.21.0.0

- added missing files

1.2.0.0

-added html file

1.1.0.0

-added AddPicture command

MATLAB Release Compatibility
Created with R2015b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: Matlab to MSWord function library