jacob调用ocx控件出错

import com.jacob.activeX.*;
import com.jacob.com.*; 


public class WordMacroCtrl {
 public void callWordMacro(String filePath,String macroName){
ActiveXComponent wrdCom=new ActiveXComponent("Word.Application");
wrdCom.setProperty("Visible", new Variant(true));
Dispatch oDocuments  =  wrdCom.getProperty( " Documents " ).toDispatch();
Dispatch oDcument =Dispatch.call(oDocuments,  "Open" , filePath).toDispatch();
Dispatch.call(wrdCom,"Run", new Variant("Normal.NewMacros."+macroName));
 
 }
 
 public static void main(String[] argv) { 
   
WordMacroCtrl Ma=new  WordMacroCtrl();
Ma.callWordMacro("D:\\MacroTest.doc", "MyMacro");
 } 


}





为什么运行时总是出错


Exception in thread "main" com.jacob.com.ComFailException: Can't map name to dispid:  Documents 

at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.activeX.ActiveXComponent.getProperty(ActiveXComponent.java)
at WordMacroCtrl.callWordMacro(WordMacroCtrl.java:11)
at WordMacroCtrl.main(WordMacroCtrl.java:20)

你可能感兴趣的:(jacob调用ocx控件出错)