Launch Visio and VBA Program from a Different Application

Started by AlexHP, December 08, 2015, 01:13:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AlexHP

OK, here's a new one...

The Visio document/template I am working on (a wiring diagram) will need to be opened by a third-party application and will need to run a couple of VBA programs I have set up in the document.  The third-party application will pass some values to the VBA in the document and then execute the programs.  Currently, these values are filled in using a dialog box (user form) that the user fills in and then the program runs upon the user clicking the OK button.  The program is included in the code section of the user form.

So, if I want to have the values provided by the third-party application instead, what do I need to do to my current program set up to allow this to happen?  Any help will be greatly appreciated.  Thank you.

Alex...

aledlund

consider using a persistent event in your document to assist in reading and parsing the command line that starts the application.

AlexHP


Croc

This code works in Access. It opens Visio, runs two macros, and closes the drawing.

    Dim vApp
    Dim vDoc
    Set vApp = CreateObject("Visio.Application")
    Set vDoc = vApp.Documents.Open(Module1.BoardPath)
    Call vDoc.RefreshData   'macro in Visio for refreshing of drawing
    Call vDoc.SavePDF       'macro for saving
    vDoc.Close
    vApp.Quit


This is what you need?

---------------------
P.S. I'm apologize, code of VB6  :)

AlexHP

This looks like what I am looking for. I will have to test it out. What about passing values to variables which will be in the programs being run after opening the document? The third-party app will be providing these values to the Visio document VBA program. Thank you.

Alex...

Croc

My Visio macro after running connects to the source and takes the data.
But you have an object vDoc. Data can be transfered for example through the document's cell.

AlexHP

The data will have to be passed to the Visio VBA. The wiring diagram is part of a set of programs which will be run after a customer makes certain selections in a web-based application. Then when they are finished, the web-based application will create a set of documents for the customer's submittal package. The wiring diagram is part of that so the web-based app will pass information, like the model number, to the Visio VBA which then parses the model number and turns on or off certain layers in the document to match up with the customer's selection. When that finishes, the document is printed to PDF. So, the Visio VBA cannot get the data from the source program because the necessary data only exists temporarily and I don't know where it will be located. Therefore, the data needs to be passed to the parsing program so it can set values in the document sheet so that formulas in the layer properties of the various pages can turn on or off the necessary layers.  :o  Easy, right...?

Yacine

Right, that's easy.
There are at least two strategies to handle the problem.
1) Use the CALLTHIS method from the external App to run the macro within Visio and pass all the parameters needed.
https://msdn.microsoft.com/en-us/library/ms406651%28v=office.12%29.aspx
2) Write the data in the document from within the external app, then use CALLTHIS.
Probably something like:
    Dim vApp
    Dim vDoc
    Set vApp = CreateObject("Visio.Application")
    Set vDoc = vApp.Documents.Open(Module1.BoardPath)

vDoc.sheet.cells("Prop.Sonso").FormulaU=chr(34)&myData&chr(34)
CallThis "myMacro" 'The macro will make use of the data of the document

    vDoc.Close
    vApp.Quit
Yacine

AlexHP

Looks great, Yacine. This might just work for me. I appreciate your help.

Alex...