如何在 VBA 中的形状之间复制 Visio 形状表部分

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/425763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:09:40  来源:igfitidea点击:

How to copy a Visio shapesheet section between shapes in VBA

vbavisioshapesheet

提问by Jon Fournier

Is there a method available for copying a section out of a shape to another shape using VBA? I'm specifically trying to copy all the custom properties and user cells from one pagesheet to another page.

有没有一种方法可以使用 VBA 将一个形状的一部分复制到另一个形状?我特别想将所有自定义属性和用户单元格从一个页面复制到另一个页面。

回答by

Unfortunately there isn't a simple method to do this. You will have to loop over all the rows in the source sheet and create the same rows in the destination sheet. E.g.:

不幸的是,没有一种简单的方法可以做到这一点。您必须遍历源工作表中的所有行并在目标工作表中创建相同的行。例如:

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 have to copy a large number of rows and performance is a consideration you should investigate using AddRowsand SetFormulas.

如果您必须复制大量行并且性能是一个考虑因素,您应该使用AddRowsSetFormulas进行调查。