Book a Demo

Author Topic: Error in Javascript when automating Visio  (Read 3992 times)

Mhatch

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Error in Javascript when automating Visio
« on: April 24, 2014, 09:05:35 am »
I have a script that automates creating diagrams in Visio.  I have been porting it from a 'JScript' to 'JavaScript' type scripts (select 'New JavaScript' in the Scripting window).

In JavaScript, I am getting errors when trying to call methods on the Visio automation object  "'Object.method' is not a function" that I cannot resolve.  The same code works great in JScript, but not in JavaScript.  Anyone know why?  

Here is the script for you to try.  The last call to Visio.ActivePage.PageSheet.CellsSRC fails with 'CellSRC is not a function'.
Code: [Select]
function main()  {
      var Visio = new COMObject("Visio.Application");
      Visio.Documents.AddEx("Basic Diagram (US Units).vst", 6, false, false);
[highlight]      Visio.ActivePage.PageSheet.CellsSRC(1, 10, 0).FormulaU = "8.5 in";
[/highlight]}

main();

Looking at the Visio object model, CellSRC is actually a property of the object that takes parameters, so apparently the COMObject function behaves differently than ActiveXObject when creating the types for execution.  

Here is the link to the Visio automation documentation for this object: http://msdn.microsoft.com/en-us/library/office/dn480902(v=office.15).aspx
« Last Edit: April 24, 2014, 09:08:02 am by mike.hatch »

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Error in Javascript when automating Visio
« Reply #1 on: April 24, 2014, 09:51:50 am »
From my experience, Javascript isn't very good for working with COM objects.  I'd suggest going back to using JScript.  The two languages are very similar, but JScript is much better for working with COM / ActiveX.
« Last Edit: April 24, 2014, 09:52:11 am by AaronB »