How to copy a section of a Visio form between shapes in VBA

Is there a way to copy a section from a form to another form using VBA? I am specifically trying to copy all custom properties and user cells from one sheet to another page.

+1


source to share


1 answer


Unfortunately, there is no easy way to do this. You will need to iterate over all the lines in the original sheet and create the same lines in the destination sheet. For example:.

Dim oPageSheet1 As Visio.Shape
Dim oPageSheet2 As Visio.Shape
Dim rowName     As String
Dim i   As Integer

Set oPageSheet1 = Visio.ActiveDocument.Pages.Item(1).PageSheet
Set oPageSheet2 = Visio.ActiveDocument.Pages.Item(2).PageSheet

i = visRowUser

While oPageSheet1.CellsSRCExists(visSectionUser, i, visUserValue, False)
    oPageSheet2.AddNamedRow visSectionUser, oPageSheet1.Section(visSectionUser).Row(i).NameU, 0
    oPageSheet2.Section(visSectionUser).Row(i).Name = oPageSheet1.Section(visSectionUser).Row(i).Name
    oPageSheet2.CellsSRC(visSectionUser, i, visUserValue).FormulaU = oPageSheet1.CellsSRC(visSectionUser, i, visUserValue).FormulaU
    oPageSheet2.CellsSRC(visSectionUser, i, visUserPrompt).FormulaU = oPageSheet1.CellsSRC(visSectionUser, i, visUserPrompt).FormulaU
    i = i + 1
Wend

      



If you need to copy a large number of rows and performance will be considered with AddRows and SetFormulas .

+1


source







All Articles