如何通过JACOB库更改Visio中的活动页面

时间:2012-03-28 16:02:51

标签: java visio jacob

我可以在Visio中使用VBA代码(使用Macro Recorder)在Visio中将活动页面从X页面更改为“主页”

Application.ActiveWindow.Page = Application.ActiveDocument.Pages.ItemU("Main")

我尝试使用JACOB Library在java中进行翻译。

visio.projects = new ActiveXComponent("Visio.Application"); 
visio.projects.setProperty("Visible", new Variant(true));
Dispatch documents = 
     new ActiveXComponent(visio.projects.getProperty("Documents").toDispatch());
Dispatch.call(documents, "open", new Variant(fileName));
// up now a try for vba Code Translation
Dispatch activeWindow = Dispatch.get(visio.projects,"ActiveWindow").toDispatch();
Dispatch page = Dispatch.get(activeWindow, "page").toDispatch();
Dispatch activeDocument = Dispatch.get(visio.projects, "ActiveDocument").toDispatch();
Dispatch pages = Dispatch.get(activeDocument, "Pages").toDispatch();
//Dispatch actualPage = Dispatch.call(pages, "ItemU", new Variant("Main")).toDispatch(); // goes wrong
// What is next???

我试图完成它,但直到现在我还没有改善。

1 个答案:

答案 0 :(得分:1)

它适用于此代码。

// up now a try for vba Code Translation
ActiveXComponent activeWindow = new ActiveXComponent(visio.projects.getProperty("ActiveWindow").toDispatch());  
ActiveXComponent activeDocument = new ActiveXComponent(visio.projects.getProperty("ActiveDocument").toDispatch());
ActiveXComponent pages = new ActiveXComponent(activeDocument.getProperty("Pages").toDispatch());
Dispatch itemU = ActiveXComponent.call(pages, "itemU", "Main").toDispatch();
activeWindow.setProperty("Page", itemU);