Skip to main content

Experimenting with Visio and VBScript


This diagram is created:




















 
 
 
 
 
 
 
using this code:

















































 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Copy the code:

Option Explicit

Dim strVSDPath, filesys
Dim vsoApplication, vsoDocument, vsoPages, vsoPage
Dim vsoMaster1, vsoMaster2, vsoStencil
Dim vsoShape1, vsoShape2, vsoConnector1
Dim itr

Const visAutoConnectDirDown = 2     'Connect down.
Const visAutoConnectDirLeft = 3     'Connect to the left.
Const visAutoConnectDirNone = 0     'Connect without relocating the shapes.
Const visAutoConnectDirRight = 4     'Connect to the right.
Const visAutoConnectDirUp = 1         'Connect up.

' Visio file to be created.
strVSDPath = "D:\Workspace_Visio\TestRunFlow.vsd"

'delete any previously existing Suite file
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(strVSDPath) Then
    filesys.DeleteFile strVSDPath
End If
Set filesys = Nothing

' Bind to Visio object.
On Error Resume Next
'Set vsoApplication = CreateObject("Visio.Application")
Set vsoApplication = CreateObject("Visio.InvisibleApp")

If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "Visio application not found."
    Wscript.Quit
End If
On Error GoTo 0


Set vsoDocument = vsoApplication.Documents.Add("Basic Diagram.vst")
Set vsoPages = vsoDocument.Pages
Set vsoPage = vsoPages.Item(1)
Set vsoStencil = vsoApplication.Documents("Basic Shapes.vss")

Set vsoMaster1 = vsoStencil.Masters("Rectangle")
'Set vsoMaster2 = vsoStencil.Masters("Rectangle")

Set vsoShape1 = vsoPage.Drop(vsoMaster1, 3.5, 7)
vsoShape1.Text = "Shape 1"
For itr = 2 to 3   
    Set vsoShape2 = vsoPage.Drop(vsoMaster1, 3.5, 5.5 + (itr - 1)*2)
   
    vsoShape2.Text = "Shape " & itr

    vsoShape1.AutoConnect vsoShape2, visAutoConnectDirDown
   
    Set vsoShape1 = vsoShape2
    Set vsoShape2 = Nothing
Next

vsoDocument.SaveAs strVSDPath
vsoDocument.Close

vsoApplication.Quit


'Set vsoApplication = Nothing
Set vsoShape1 = Nothing
Set vsoShape2 = Nothing
Set vsoConnector1 = Nothing

Set vsoMaster2 = Nothing
Set vsoMaster1 = Nothing
Set vsoStencil = Nothing
Set vsoPage = Nothing
Set vsoPages = Nothing
Set vsoDocument = Nothing
Set vsoApplication = Nothing

Wscript.Echo "Done"

Comments

Popular posts from this blog

Multi XSD XML Validation

  This program validates XMLs against referenced XSDs. The XSDs are assumed to be external to (not embedded in) the XML. List the XSDs and XMLs details in separate sheets in the program’s excel book and run the program. The program will generate errors/ warnings in console window.

Two-way XML Diffgram (XML structure sensitive)

     With pretty printed source XMLs: Same source XMLs, but in single line – diffgram output remains the same: Download the program files from here .

Study of an AngularJS application: Feeding Excel based data into an SVG Flowchart with AngularJS and NodeJS

Reference article Implementing a Flowchart with SVG and AngularJS Source code from original article is here .   Customization goals a) Feed the SVG flowchart nodes from excel datasheet b) Understand a bit of the AngularJS and NodeJS client-server communication c) Learn javascript debugging on server side as well as client side using VS Code editor As a beginner to AngularJS-NodeJS, the customization is based on a partial study of the original article .   Most challenging challenge as a dummy There was a space of time when I thought I was publishing the server side JSON data to the same URL as the front-end html page. And then trying to debug it and not knowing why: in one case the data was coming from the server side only, while in the other case it was coming from mocked data on client side. Kept on looking for whether data was getting lost, or did I need routing. There were debug sessions where both server side and client side individually appear...