[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Tips and examples for becoming a proficient Visio VB programmer

Posted on 2007-10-01
5
Medium Priority
?
1,508 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:PeterFrb
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:EuroHammer
ID: 19996684
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
 

Author Comment

by:PeterFrb
ID: 19999954
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
 

Author Comment

by:PeterFrb
ID: 20000067
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
 
LVL 2

Accepted Solution

by:
EuroHammer earned 2000 total points
ID: 20020858
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
 

Author Comment

by:PeterFrb
ID: 20026565
I will do so.  The ability to record Visio macros is completely worth the expense.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Book Review: Using Microsoft Visio 2010 by Chris Roth   Disclaimer: The author of Using Visio 2010 is a friend and fellow Visio MVP. Whether you’re new to Visio or are upgrading to Visio 2010 from a previous version, you will find a lot to like…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month18 days, 17 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question