2

I can change a activePage in Visio with VBA code (with Macro Recorder) in Visio for Example from X Page to page "Main"

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

I tried it translate in java with JACOB Library.

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???

i'am trying it to complete but until now i have no Improvment.

Tolga Ulusoy
  • 143
  • 1
  • 7

1 Answers1

1

it works with this Code.

// 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);
Tolga Ulusoy
  • 143
  • 1
  • 7