Excel有很好的流程圖製作工具菜單,其製作方法也有很多,相對也比較簡單。
但是,如果不熟悉製作過程的情況下,還是有一定的難度的。
前言
通過代碼來簡化製作流程,就是說把製作方法都省去,直接把所有工作都集中到一個按鈕上面來。
這樣的製作就簡單了多了。
下面通過代碼來做一個簡單流程圖製作過程。
方法
打開界面,可以看到左側是已經製作完成的一個示例。
其方法就是在右側文本框內輸入結構標籤,單擊製作按鈕就自動添加進行了。
其實,這個功能還沒有完全符合製作整個完整過程。
比如,如何刪除,或插入一個標籤。
考慮到其編碼可能比較多,時間關係也就沒有做。
不過,做一個簡單過程還是可以完成的。
關鍵代碼
AddShape(msoShapeRectangle, 150, 80, 150, 30)'添加矩形框AddConnector(msoConnectorStraight, 100, 100, 150, 100)'添加菱形框AddConnector(msoConnectorStraight, 100, 100, 150, 100).ConnectorFormat'創建一個連接符
掌握上面三條代碼,就基本掌握了流程圖形裡面如何添加圖形的基本操作了,具體方法,文後有代碼可查看。
代碼
順序結構函數
Private Sub AddRectShape(m As Worksheet, FirstShape As Shape, Titels As String)Dim s As Shapes, SecondShape As Shape, ShapeConn As Object Dim sWidth As Integer, sHeight As Integer sWidth = 150 sHeight = 30 Set s = Me.Shapes Set SecondShape = s.AddShape(msoShapeRectangle,_ FirstShape.Left, sHeight + FirstShape.Top + FirstShape.Height, sWidth, sHeight) With SecondShape.TextFrame .HorizontalAlignment = xlVAlignCenter .VerticalAlignment = xlVAlignCenter With .Characters .Text = Titels With .Font .Size = 12 .Name = "微軟雅黑" End With End With End With Set ShapeConn = s.AddConnector(msoConnectorStraight, 100, 100, 150, 100).ConnectorFormat With ShapeConn .BeginConnect connectedshape:=FirstShape, connectionsite:=3 .EndConnect connectedshape:=SecondShape, connectionsite:=1 End WithEnd Sub
分支結構函數
Private Sub AddDiamondShape(m As Worksheet, FirstShape As Shape, Titels As String)Dim s As Shapes, SecondShape As Shape, ShapeConn As Object Dim sWidth As Integer, sHeight As Integer sWidth = 150 sHeight = 60 Set s = Me.Shapes Set SecondShape = s.AddShape(msoShapeDiamond,_ FirstShape.Left, FirstShape.Top + sHeight, sWidth, sHeight) With SecondShape.TextFrame .HorizontalAlignment = xlVAlignCenter .VerticalAlignment = xlVAlignCenter With .Characters .Text = Titels With .Font .Size = 12 .Name = "微軟雅黑" End With End With End With Set ShapeConn = s.AddConnector(msoConnectorStraight, 100, 100, 150, 100).ConnectorFormat With ShapeConn .BeginConnect connectedshape:=FirstShape, connectionsite:=3 .EndConnect connectedshape:=SecondShape, connectionsite:=1 End WithEnd Sub
如這篇文章對你有幫助
歡迎關注、收藏