Can I copy shape data between different sheets

Hi, I have been trying out the Off-page connector but this does not seem to do what I want. It has an option to synchronise "text" of a shape, but I want to synchronise shape data. My shapes on both pages would have the same shape data fields defined.

I have figured out I can move the active page pointer to another page and then reference shapes on that page. Alternatively is there a way to put the page name as an index into the reference for the shape I am interested in ? I can't seem to find syntax for this.
ie instead of;

set active page 1
global = shape data

set active page 2
shape data = global

can I say;

page.shape.data = page.shape.data ?
adlikonAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Scott HelmersConnect With a Mentor Visio Consultant, Trainer, Author, and DeveloperCommented:
Unfortunately, "shape data" is not a single entity; each shape data field actually consists of multiple items (shapesheet cells, to be specific) that need to be copied in order to replicate that field.

Consequently. you have to loop through the shape data section, copying all the cells for each data field.

The code below should do what you want. As you'll see, both the from/to page names and the from/to shape IDs are hardcoded -- you'll need to substitute your own page names and shape IDs.

Let me know if you have any questions or want me to attach a Visio file with this code in it.
Scott
Sub Copy_Shape_Data_Page_to_Page()
' If named row already exists in TO shape, overwrites its cell values,
' otherwise creates a new row
'
' Does not affect shape data rows in TO shape if row names don't match
' those in the FROM shape
 
    Dim pgFrom As Visio.Page, pgTo As Visio.Page
    Dim shpFrom As Visio.Shape, shpTo As Visio.Shape
    Dim rowFrom As Visio.Row, rowTo As Visio.Row
    
    Dim ixFromRow As Integer, ixToRow As Integer
    Dim ixCol As Integer
        
    ' Select FROM page and shape
    Set pgFrom = ActiveDocument.Pages("Page-1")
    Set shpFrom = pgFrom.Shapes("Sheet.1")
    
    ' Select TO page and shape
    Set pgTo = ActiveDocument.Pages("Page-2")
    Set shpTo = pgTo.Shapes("Sheet.1")
    
    ' Create shape data section if it doesn't already exist
    If Not shpTo.SectionExists(visSectionProp, False) Then
        shpTo.AddSection (visSectionProp)
    End If
    
    For ixFromRow = 0 To shpFrom.RowCount(visSectionProp) - 1
        Set rowFrom = shpFrom.Section(visSectionProp).Row(ixFromRow)
        
        If shpTo.CellExists("Prop." & rowFrom.Name, False) Then
            ' Named row already exists so get its row number
            ixToRow = shpTo.CellsRowIndex("Prop." & rowFrom.Name)
        Else
            ' Row doesn't exists so create it and get its row number
            ixToRow = shpTo.AddNamedRow(visSectionProp, rowFrom.Name, visTagDefault)
        End If
                
        For ixCol = 0 To shpFrom.RowsCellCount(visSectionProp, ixRow) - 1
            shpTo.CellsSRC(visSectionProp, ixToRow, ixCol).FormulaForceU = _
            shpFrom.CellsSRC(visSectionProp, ixFromRow, ixCol).FormulaU
        Next ixCol
    Next ixFromRow
 
End Sub

Open in new window

0
 
adlikonAuthor Commented:
Super. I am building a stencil so I probably won't go for the 'full monty' validation to see if cells exist as users will not be creating new shapes or shape data with the macros I am creating. Cheers
0
All Courses

From novice to tech pro — start learning today.