• visio vba code (2002 sr1)

    Author
    Topic
    #378340

    I need to create some code that performs the following:

    for every page in the active visio document:
    1) remove the background
    2) select all connectors and change to weight 1 (hairline?)
    3) set the zoom to “page” (instead of x%)

    I have had a go at (1) using the help, this seems to work:

    Public Sub changeBackPage()

    Dim pagsObj As Visio.Pages ‘Pages collection
    Dim pagObj As Visio.Page ‘current page in collection
    Dim i As Integer ‘current index into collection
    Dim bg As String
    ‘Retrieve the Pages collection.
    Set pagsObj = ActiveDocument.Pages

    bg = “”

    ‘Iterate through the collection.
    For i = 1 To pagsObj.Count

    ‘Retrieve the Page object at the current index.
    Set pagObj = pagsObj(i)

    pagObj.BackPage = bg

    Next i

    End Sub

    Viewing 0 reply threads
    Author
    Replies
    • #626127

      This seems to work, but please note that…

      • It is my first ever Visio program
      • I wrote and tested it on Visio 2000
      • It has had very limited testing
        [/list]Public Sub SRTest()
        Dim pg As Page
        Dim shp As Shape

        For Each pg In ActiveDocument.Pages
        pg.BackPage = “”
        For Each shp In pg.Shapes
        If shp.Cells(“ObjType”) = 2 Then
        shp.Cells(“lineweight”).Formula = “1 pt”
        End If
        Next shp
        Next pg

        ActiveWindow.Zoom = -1

        End Sub

        StuartR

      • #626152

        Thanks Stuart, seems to work fine.

        It is able to seperate connectors from lines and boxes and also capture connectors whether they are attached to other shapes or not

        Just what I needed

        BTW are you able to explain the line cells(“objType”) in laymans terms. I didn’t understand the help for cells and have looked through all the properties for “shp” but can’t find objtype (object type exists but has a different value)

        Simon

        • #626160

          The first thing to note about Visio is that every shape on the page has a Shape Sheet, this is like a spreadsheet and completely defines the shape.

          Shape.Cells( ) gives you access to the shape sheet, you can see the cells from the normal Visio user interface by selecting an object and then Windows > Show ShapeSheet.

          One of the Cells in the ShapeSheet, under the Miscellaneous category is ObjType. Values for this cell can be found on the MSDN web site at http://msdn.microsoft.com/library/default….nectors_916.asp[/url]. An object type of 2 corresponds to “Shape is routable. Must be a 1-D shape”, which is what you mean by a connector. A routable 1 dimensional shape!

          I learned a lot writing this one, thank you.

          StuartR

          • #626167

            Crumbs, sometimes these things are like peeling onions – just when you think you understand whats going on someone peels the layer off and shows you something completely new.

            Thanks for your help I have learnt heaps too.

            Simon

            thanks also for giving me the opportunity to become a starlounger (simple things for simple minds)

            • #645243

              OR, you could just use whilst iterating through a pages shapes collection:
              If shape.style = “Connector” then
              <>
              end if

              Alan
              Cheshire
              UK

    Viewing 0 reply threads
    Reply To: visio vba code (2002 sr1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: