Shapes_Get_Coordinates.bas 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. Sub Shapes_Get_Coordinates()
  2. '// 建立文件 testfile.txt 输出物件坐标信息
  3. Set fs = CreateObject("Scripting.FileSystemObject")
  4. Set f = fs.CreateTextFile("R:\testfile.txt", True)
  5. ActiveDocument.Unit = cdrMillimeter
  6. Dim OrigSelection As ShapeRange
  7. Set OrigSelection = ActiveSelectionRange
  8. '// 代码运行时关闭窗口刷新
  9. Application.Optimization = True
  10. With OrigSelection
  11. MsgBox "选择物件个数 " & OrigSelection.Count & " 尺寸:" & .SizeWidth & " x " & .SizeHeight
  12. f.WriteLine ("选择物件个数 " & OrigSelection.Count & " 尺寸:" & .SizeWidth & " x " & .SizeHeight)
  13. lx = OrigSelection.LeftX
  14. rx = OrigSelection.RightX
  15. by = OrigSelection.BottomY
  16. ty = OrigSelection.TopY
  17. f.WriteLine ("选择物件集合坐标范围: " & "(" & lx & "," & by & ") " & "(" & rx & "," & by & ") " _
  18. & "(" & lx & "," & ty & ") " & "(" & rx & "," & ty & ") ")
  19. f.WriteLine ("--------- 分割 ---------")
  20. End With
  21. Dim s1 As Shape
  22. cnt = 1
  23. For Each Target In OrigSelection
  24. Set s1 = Target
  25. lx = s1.LeftX
  26. rx = s1.RightX
  27. by = s1.BottomY
  28. ty = s1.TopY
  29. '// 遍历物件,输出左下-右下-左上-右上四点坐标
  30. f.WriteLine (cnt & "号物件坐标: " & "(" & lx & "," & by & ") " & "(" & rx & "," & by & ") " _
  31. & "(" & lx & "," & ty & ") " & "(" & rx & "," & ty & ") ")
  32. cnt = cnt + 1
  33. Next Target
  34. f.Close
  35. '// 代码操作结束恢复窗口刷新
  36. Application.Optimization = False
  37. ActiveWindow.Refresh
  38. Application.Refresh
  39. End Sub