How do I update fields in a Word document using activeX in MATLAB?

I used MATLAB to add a new figure to a Word document and would like to update the figures list.
hWord = actxserver('word.application');
hWord.Visible = 1;
hDocs = hWord.documents;
hDoc = hDocs.Add;
hDoc.Activate;
hDoc.fields.update
When I run this script, I get the following error: 
'update' needs one of the following:
Database Toolbox
Fuzzy Logic Toolbox
Instrument Control Toolbox
Predictive Maintenance Toolbox
Robotics System Toolbox
Simulink Control Design
Simulink Real-Time Statistics and Machine Learning Toolbox
System Composer
error test (line 11)
  hDoc.fields.update
How do I update the fields in my Word document?

 Accepted Answer

The “update” function call searches for a MATLAB function of that name, which can be found in the MATLAB Toolboxes listed in the error message. To update the fields within your Word document, use the Microsoft VBA method “Update”: 
hDoc.fields.Update 
Microsoft VBA methods can be identified from MATLAB functions by the capitalization, such as in “hdocs.Add”. Refer to the official Microsoft documentation for information on VBA methods. 

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!