前言
python虽然能够绘制visio流程图,但是需要进行安装,本文参考mscn提供了一个visio自带的vb脚本创建流程图的方法。
一、参考网址
二、使用步骤
1.创建宏
按下Alt+F8 或在菜单栏选择“视图->宏”
添入VB代码
Sub DrawProcess()
Dim vsoDocumentStencil As Document
Dim vsoStencilDocument As Document
Dim vsoPage As Page
Dim vsoMasterProcess As Master
Dim vsoMasterDecision As Master
Dim vsoMasterSubProcess As Master
Dim vsoMasterContainer As Master
Dim vsoShapeProcess1 As Shape
Dim vsoShapeProcess2 As Shape
Dim vsoShapeProcess3 As Shape
Dim vsoShapeProcess4 As Shape
Dim vsoShapeToSubProcessA As Shape
Dim vsoShapeToSubProcessB As Shape
Dim vsoShapeDecision1 As Shape
Dim vsoShapeDecision2 As Shape
Dim vsoShapeSelection1 As Shape
Dim vsoShapeSelection2 As Shape
Dim vsoShapeContainer As Shape
Dim vsoSelection As Selection
Dim intDiagramServices As Integer
intDiagramServices = ActiveDocument.DiagramServicesEnabled
intDiagramServices = visServiceVersion140
' Specify masters to drop.
Set vsoMasterProcess = Visio.Documents("BASFLO_M.VSS").Masters.ItemU("Process")
Set vsoMasterDecision = Visio.Documents("BASFLO_M.VSS").Masters.ItemU("Decision")
Set vsoMasterSubProcess = Visio.Documents("BASFLO_M.VSS").Masters.ItemU("Subprocess")
' Set the Page object equal to the first page.
Set vsoPage = ThisDocument.Pages(1)
' Create the first process shape.
Set vsoShapeProcess1 = vsoPage.Drop(vsoMasterProcess, 3, 4.5)
vsoShapeProcess1.Text = "流程 1"
' Create and connect the first decision shape.
Set vsoShapeDecision1 = vsoPage.DropConnected(vsoMasterDecision, vsoShapeProcess1, visAutoConnectDirRight)
vsoShapeDecision1.Text = "判断"
' Create and connect the second process shape.
Set vsoShapeProcess2 = vsoPage.DropConnected(vsoMasterProcess, vsoShapeDecision1, visAutoConnectDirRight)
vsoShapeProcess2.Text = "流程 2"
' Create and connect one shape to link to a subprocess.
Set vsoShapeToSubProcessA = vsoPage.DropConnected(vsoMasterProcess, vsoShapeDecision1, visAutoConnectDirDown)
vsoShapeToSubProcessA.Text = "子流程A"
' Create and connect another shape to link to a subprocess.
Set vsoShapeToSubProcessB = vsoPage.DropConnected(vsoMasterProcess, vsoShapeToSubProcessA, visAutoConnectDirDown)
vsoShapeToSubProcessB.Text = "子流程B"
' Create and connect the second decision shape.
Set vsoShapeDecision2 = vsoPage.DropConnected(vsoMasterDecision, vsoShapeProcess2, visAutoConnectDirRight)
vsoShapeDecision2.Text = "判断"
' Create and connect the third process shape.
Set vsoShapeProcess3 = vsoPage.DropConnected(vsoMasterProcess, vsoShapeDecision2, visAutoConnectDirRight)
vsoShapeProcess3.Text = "流程 3"
' Create and connect the fourth process shape.
Set vsoShapeProcess4 = vsoPage.DropConnected(vsoMasterProcess, vsoShapeDecision2, visAutoConnectDirDown)
vsoShapeProcess4.Text = "流程 4"
Set vsoShapeSelection1 = vsoPage.Shapes.Item(6)
Set vsoShapeSelection2 = vsoPage.Shapes("流程.8")
ActiveWindow.DeselectAll
Set vsoSelection = ActiveWindow.Selection
' Select two shapes to add to a container.
vsoSelection.Select vsoShapeSelection1, visSelect
vsoSelection.Select vsoShapeSelection2, visSelect
' Draw a container around the shapes.
Set vsoStencilDocument = Application.Documents.OpenEx(Application.GetBuiltInStencilFile(visBuiltInStencilContainers, visMSMetric), visOpenHidden)
Set vsoShapeContainer = Application.ActivePage.DropContainer(vsoStencilDocument.Masters.ItemU("Container 5"), vsoSelection)
vsoShapeContainer.Text = "子流程 模块"
vsoStencilDocument.Close
End Sub
2.运行宏
Alt+F8打开宏对话框,单击运行
3.运行结果
运行结果
总结
这样非常方便,后续考虑搞一个通过读剪切板实现快速流程图的vb宏程序,方便后续批量快速绘制流程图,减少ctrl+c/v的次数。