Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Feb 2001
    Location
    Auckland, North Island, New Zealand
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    visio vba code (2002 sr1)

    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

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: visio vba code (2002 sr1)

    This seems to work, but please note that...

    <UL><LI>It is my first ever Visio program
    <LI>I wrote and tested it on Visio 2000
    <LI>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

  3. #3
    Star Lounger
    Join Date
    Feb 2001
    Location
    Auckland, North Island, New Zealand
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: visio vba code (2002 sr1)

    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

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: visio vba code (2002 sr1)

    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. 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

  5. #5
    Star Lounger
    Join Date
    Feb 2001
    Location
    Auckland, North Island, New Zealand
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: visio vba code (2002 sr1)

    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)

  6. #6
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Warrington, Cheshire
    Posts
    355
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: visio vba code (2002 sr1)

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

    Alan
    Cheshire
    UK

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •