Tips and examples for becoming a proficient Visio VB programmer

I am a proficient VB developer in Word, Access, Excel, and VB6.  I would like to become one in Visio.  I would like to know of a site or two that would have lots of examples of VB code doing commonplace things in Visio, like the code to drag and drop an item from a stencil to a document being a prime example.  Further, I wonder if it's possible to have Visio record my actions and give me the code it produced, the way Word and Excel do.  Thanks much, Peter Ferber
PeterFrbWeb development, Java scripting, Python TrainingAsked:
Who is Participating?
 
Paul PayneConnect With a Mentor Managing ConsultantCommented:
I am using Visio 2003 Standard (Version 11) which is available as an upgrade from Amazon for £75 but they quote 4-6 weeks delivery??  You might need to check what version you need to be able to upgrade?
0
 
Paul PayneManaging ConsultantCommented:
Hi,
You can use Visio the same as Excel etc.  You can get the VBA editor up by using Alt + F11, you can create macros using Tools>Macros>Record New Macro.  Below is some sample code to add three process boxes and name them Process 1, Process 2 and Process 3.  Have fun learn some new stuff.

 Application.Documents.OpenEx "basflo_m.vss", visOpenRO + visOpenDocked

    Application.Windows.ItemEx("Drawing5").Activate
    Application.ActiveWindow.Page.Drop Application.Documents.Item("BASFLO_M.VSS").Masters.ItemU("Process"), 3.937008, 10.334646

    Application.Windows.ItemEx("Drawing5").Activate
    Application.ActiveWindow.Page.Drop Application.Documents.Item("BASFLO_M.VSS").Masters.ItemU("Process"), 3.937008, 9.153543

    Application.Windows.ItemEx("Drawing5").Activate
    Application.ActiveWindow.Page.Drop Application.Documents.Item("BASFLO_M.VSS").Masters.ItemU("Process"), 3.937008, 7.972441

    Dim UndoScopeID1 As Long
    UndoScopeID1 = Application.BeginUndoScope("Drop On Page")
    Dim vsoShape1 As Visio.Shape
    Set vsoShape1 = Application.ActiveWindow.Page.Drop(Application.ConnectorToolDataObject, 3.937008, 10.03937)
    vsoShape1.CellsSRC(visSectionObject, visRowXForm1D, vis1DBeginX).ResultIU = 3.937008
    vsoShape1.CellsSRC(visSectionObject, visRowXForm1D, vis1DBeginY).ResultIU = 10.03937
    vsoShape1.CellsSRC(visSectionObject, visRowXForm1D, vis1DEndX).ResultIU = 3.937008
    vsoShape1.CellsSRC(visSectionObject, visRowXForm1D, vis1DEndY).ResultIU = 9.448819
    Dim vsoCell1 As Visio.Cell
    Dim vsoCell2 As Visio.Cell
    Set vsoCell1 = Application.ActiveWindow.Page.Shapes.ItemFromID(4).CellsU("BeginX")
    Set vsoCell2 = Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(7, 2, 0)
    vsoCell1.GlueTo vsoCell2
    Set vsoCell1 = Application.ActiveWindow.Page.Shapes.ItemFromID(4).CellsU("EndX")
    Set vsoCell2 = Application.ActiveWindow.Page.Shapes.ItemFromID(2).CellsSRC(7, 3, 0)
    vsoCell1.GlueTo vsoCell2
    Application.EndUndoScope UndoScopeID1, True

    Dim UndoScopeID2 As Long
    UndoScopeID2 = Application.BeginUndoScope("Drop On Page")
    Dim vsoShape2 As Visio.Shape
    Set vsoShape2 = Application.ActiveWindow.Page.Drop(Application.ConnectorToolDataObject, 3.937008, 8.858268)
    vsoShape2.CellsSRC(visSectionObject, visRowXForm1D, vis1DBeginX).ResultIU = 3.937008
    vsoShape2.CellsSRC(visSectionObject, visRowXForm1D, vis1DBeginY).ResultIU = 8.858268
    vsoShape2.CellsSRC(visSectionObject, visRowXForm1D, vis1DEndX).ResultIU = 3.937008
    vsoShape2.CellsSRC(visSectionObject, visRowXForm1D, vis1DEndY).ResultIU = 8.267717
    Dim vsoCell3 As Visio.Cell
    Dim vsoCell4 As Visio.Cell
    Set vsoCell3 = Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsU("BeginX")
    Set vsoCell4 = Application.ActiveWindow.Page.Shapes.ItemFromID(2).CellsSRC(7, 2, 0)
    vsoCell3.GlueTo vsoCell4
    Set vsoCell3 = Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsU("EndX")
    Set vsoCell4 = Application.ActiveWindow.Page.Shapes.ItemFromID(3).CellsSRC(7, 3, 0)
    vsoCell3.GlueTo vsoCell4
    Application.EndUndoScope UndoScopeID2, True

    Dim vsoCharacters3 As Visio.Characters
    Set vsoCharacters3 = Application.ActiveWindow.Page.Shapes.ItemFromID(1).Characters
    vsoCharacters3.Begin = 0
    vsoCharacters3.End = 0
    vsoCharacters3.Text = "Process 1"

    Dim vsoCharacters4 As Visio.Characters
    Set vsoCharacters4 = Application.ActiveWindow.Page.Shapes.ItemFromID(2).Characters
    vsoCharacters4.Begin = 0
    vsoCharacters4.End = 0
    vsoCharacters4.Text = "Process 2"

    Dim vsoCharacters5 As Visio.Characters
    Set vsoCharacters5 = Application.ActiveWindow.Page.Shapes.ItemFromID(3).Characters
    vsoCharacters5.Begin = 0
    vsoCharacters5.End = 0
    vsoCharacters5.Text = "Process 3"

Regards

EuroHammer
0
 
PeterFrbWeb development, Java scripting, Python TrainingAuthor Commented:
What version of Visio do you use? I have Visio Standard, which does not have the Record Macro feature.  Buying the upgrade could well be worthwhile, for that feature alone?  Can you tell me what you have and its cost?  Thanks, Peter
0
 
PeterFrbWeb development, Java scripting, Python TrainingAuthor Commented:
I am having problems with your code: I believe the version of VB I'm using is different than yours, since I'm coming across commands that my compiler doesn't recognize.
If there is any site with code snippits that perform specific finite tasks using a minimum amount of code, that would be ideal.  I've had this application for a *long* time: it's Visio Standard 5.0c, copyright 1991 - 1998.  Perhaps that's another reason to go for the upgrade.
0
 
PeterFrbWeb development, Java scripting, Python TrainingAuthor Commented:
I will do so.  The ability to record Visio macros is completely worth the expense.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.