Activating existing Visio instance from Excel VBA

Started by kagoolx, August 29, 2013, 01:15:51 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kagoolx

Hi all,

I have been writing a tool to interface with Visio from an Excel document, and have run into the following issue:

I would like to be able to manipulate shapes in an existing (open) Visio document from Excel VBA, but am unable to activate the existing instance - all I can do is create a new document to work with.  This is the code I am using to create a Visio document:

       
  ' Open Visio, create a new document, and set visioPage to refer to the new Visio page:

  Set visioApp = CreateObject("visio.application")
  Set visioDoc = visioApp.Documents.AddEx("")
  Set visioPage = visioApp.ActiveWindow.Page


Is there a method of setting the same visioApp / visioDoc / visioPage objects to an existing Visio instance?

Many thanks in advance  :)

JohnGoldsmith

Hi,

Take a look at this forum thread which describes the process from the other direction (Visio to Excel):

http://visguy.com/vgforum/index.php?topic=4992

Basically you use CreateObject to create a new application instance and GetObject to retrieve one (if one exists).

Once you've got hold of it you can then loop through the Application.Documents collection to determine if it's the document you're after (for example, by checking what template it's based on, what stencils are open with it, whether it contains a document cell of a particular name/value etc.)

Hope that helps.

Best regards

John

PS - Just out of interest, what version and edition of Visio are you targeting?
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

kagoolx

Man, thanks so much again John!  Your answers to both of my questions have been spot on.

I'm using Visio Professional 2010 and Excel 2010.  I'm building a tool which automates production of Visio documents represent IT Architectures, based upon lists of interfaces stored in Excel.