匆匆做了一下,请楼主测试。 相关例子和注释等可搜索我的部分作品。 Sub GetMyPoints() '取得线条中点 Dim myLine As Variant Dim PointsArray() As Single, X1 As Single, Y1 As Single, X2 As Single, Y2 As Single Dim X3 As Single, Y3 As Single, MyPoints As Shape, ParallelX As Byte, ParallelY As Byte On Error Resume Next '忽略错误(此处有很大作用) With Selection.ShapeRange '选定的图形对象 If .Count <> 1 Or .Type <> msoLine Then MsgBox "错误的操作!导致出错的原因可能有:" _ & vbCrLf & "1.没有选定;" & vbCrLf & "2.选定的自选图形不是直线;" _ & vbCrLf & "3.选定的线条数量超过了一条; " & vbCrLf & _ "4.其它.", vbOKOnly + vbExclamation, "Microsoft Word": Exit Sub Set myLine = .Item(1) '获得其中的对象之一 With myLine.Nodes '对象一的几何图形 PointsArray = .Item(1).Points '顶点之一坐标,是个数组 X1 = PointsArray(1, 1) 'X轴 Y1 = PointsArray(1, 2) 'Y轴 PointsArray = .Item(2).Points '顶点之二坐标 X2 = PointsArray(1, 1) 'X轴 Y2 = PointsArray(1, 2) 'Y轴 End With If X1 > X2 Then X3 = X2 + (X1 - X2) / 2 Else X3 = X1 + (X2 - X1) / 2 If Y1 > Y2 Then Y3 = Y2 + (Y1 - Y2) / 2 Else Y3 = Y1 + (Y2 - Y1) / 2 End With '定义一个圆形 Set MyPoints = ActiveDocument.Shapes.AddShape(msoShapeOval, X3 - 1, Y3 - 1, 2, 2) With MyPoints .Line.ForeColor = myLine.Line.ForeColor .Line.Weight = myLine.Line.Weight End With ActiveDocument.Shapes.Range(Array(myLine.Name, MyPoints.Name)).Group End Sub '----------------------
[此贴子已经被作者于2006-12-8 6:48:32编辑过] |