最新版Visio是否支持通过VBA修改组织结构图下属布局?
在最新版Visio中通过VBA修改组织结构图下属布局
最新版Visio支持通过VBA程序化修改组织结构图的下属布局,相比旧版调用OrgC11加载项的方式(如Call Visio.Application.Addons("OrgC11").Run("/toolbar_vert")),现在可以直接通过Shape对象的Layout属性实现,这种方式更灵活可控。
示例VBA代码
Sub ChangeSubordinateLayout() Dim orgChart As Visio.Document Set orgChart = Application.ActiveDocument Dim orgChartPage As Visio.Page Set orgChartPage = orgChart.Pages(1) Dim topLevelShape As Visio.Shape Set topLevelShape = orgChartPage.Shapes.ItemFromID(1) Dim subordinates As Visio.Shapes Set subordinates = topLevelShape.Subordinates Dim subordinateShape As Visio.Shape For Each subordinateShape In subordinates subordinateShape.Layout = VisLayoutTypes.visLORL Next subordinateShape End Sub
代码说明
- 代码默认当前活动文档的第一页为组织结构图,且顶层形状的ID为1,可根据实际场景调整参数
- 通过
topLevelShape.Subordinates获取顶层形状的所有下属节点 - 将下属形状的
Layout属性设置为VisLayoutTypes.visLORL(水平树形结构),你可以替换为其他VisLayoutTypes枚举值实现不同布局:visLOBL:从上到下的垂直树形布局visLOBR:从下到上的垂直树形布局visLORR:从右到左的水平树形布局
内容的提问来源于stack exchange,提问作者Brady Guy
相关产品推荐
相关产品推荐

