MSWord - ActiveX Fails to Invoke Objects

2019-08-28 12:25发布

问题:

After a year using the MS Word 2013 VBA through ActiveX server calls under MS Win 8 Pro x64, the following call ends in error:

ActiveDocument.FormFields

Yesterday I made a Windows Update including a Security Update for MSOffice 2013 64-bit. Today I uninstalled the update, and the problem now persists.

1. Matlab 2014b

X=actxserver('Word.Application');
XD=X.Documents.Open('file.docx');
XD.FormFields

    No appropriate method, property, or field FormField for class Interface.Microsoft_Word_15.0_Object_Library._Document.

Most simple direct calls into the ActiveX server properties still work well:

XD=X.Documents.Add;
XS=X.Selection;
XS.Font.Name='Courier New';
XS.Pagesetup.RightMargin=28.34646;
... etc

But any call for invoking a Document object (through .Documents.Add, .ActiveDocument, .Documents.Item(1), etc.) fails; listing their fields or methods shows nothing. Hence the subsequent calls to the Document object deliver no results:

XD=X.Documents.Add;
    XD = Interface.Microsoft_Word_15.0_Object_Library._Document
get(XD)
    struct with no fields.
invoke(XD)       
    <Nothing>

I also did not found any reference in Matlab Documentation to this behavior.

2. MS Word

Calls made directly inside Visual Basic Editor works fine:

MsgBox ActiveDocument.FormFields.Count

    0

I was searching in the VBA Object Browser, but it still lists the Document object including an instance of the FormFields class. But the error suggest the _Document class do not, which is not listed in the "Object Browser" when i seek by using that underscored name.

Is there any reference on why the calls to these objects fail, while the standard simpler properties still works through the ActiveX calls?

回答1:

Solution

  1. Repairing the installation

  2. The option File>Options>Trust Center>Trust Center Settings>Developer Macro Settings>Trust access to the VBA project object model is Checked, which I suppose enable the VBA calls from ActiveX Servers (That is a guess).

  3. Restart the System.