ArrangeForm.bas 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. VERSION 5.00
  2. Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} ArrangeForm
  3. Caption = "蘭雅sRGB 手动拼版"
  4. ClientHeight = 2475
  5. ClientLeft = 45
  6. ClientTop = 330
  7. ClientWidth = 4650
  8. OleObjectBlob = "ArrangeForm.frx":0000
  9. ShowModal = 0 'False
  10. StartUpPosition = 2 '屏幕中心
  11. WhatsThisButton = -1 'True
  12. WhatsThisHelp = -1 'True
  13. End
  14. Attribute VB_Name = "ArrangeForm"
  15. Attribute VB_GlobalNameSpace = False
  16. Attribute VB_Creatable = False
  17. Attribute VB_PredeclaredId = True
  18. Attribute VB_Exposed = False
  19. Private Sub CommandButton1_Click()
  20. On Error GoTo ErrorHandler
  21. API.BeginOpt
  22. Dim ls, hs As Integer: Dim lj, hj As Double
  23. Dim matrix As Variant: Dim sr As ShapeRange
  24. ls = Val(TextBox1.text)
  25. hs = Val(TextBox2.text)
  26. lj = Val(TextBox3.text)
  27. hj = Val(TextBox4.text)
  28. matrix = Array(ls, hs, lj, hj)
  29. Set sr = ActiveSelectionRange
  30. If ls * hs = 0 Then Exit Sub
  31. If ls = 1 Or hs = 1 Then
  32. arrange_Clone_one matrix, sr
  33. GoTo ErrorHandler
  34. End If
  35. '// 代码运行时关闭窗口刷新
  36. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  37. '// 拼版矩阵
  38. arrange_Clone matrix, sr
  39. Unload Me
  40. ErrorHandler:
  41. API.EndOpt
  42. End Sub
  43. '// 拼版矩阵 matrix = Array(ls, hs, lj, hj)
  44. Private Function arrange_Clone(matrix As Variant, sr As ShapeRange)
  45. ls = matrix(0): hs = matrix(1)
  46. lj = matrix(2): hj = matrix(3)
  47. x = sr.SizeWidth: Y = sr.SizeHeight
  48. Set s1 = sr.Clone
  49. '// StepAndRepeat 方法在范围内创建多个形状副本
  50. Set dup1 = s1.StepAndRepeat(ls - 1, x + lj, 0#)
  51. Set dup2 = ActiveDocument.CreateShapeRangeFromArray(dup1, s1).StepAndRepeat(hs - 1, 0#, -(Y + hj))
  52. s1.Delete
  53. End Function
  54. Private Function arrange_Clone_one(matrix As Variant, sr As ShapeRange)
  55. ls = matrix(0): hs = matrix(1)
  56. lj = matrix(2): hj = matrix(3)
  57. x = sr.SizeWidth: Y = sr.SizeHeight
  58. Set s1 = sr.Clone
  59. '// StepAndRepeat 方法在范围内创建多个形状副本
  60. If ls > 1 Then
  61. Set dup1 = s1.StepAndRepeat(ls - 1, x + lj, 0#)
  62. Else
  63. Set dup1 = s1
  64. End If
  65. If hs > 1 Then
  66. Set dup2 = ActiveDocument.CreateShapeRangeFromArray(dup1, s1).StepAndRepeat(hs - 1, 0#, -(Y + hj))
  67. End If
  68. s1.Delete
  69. End Function