ArrangeForm.frm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 'CenterScreen
  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. '// 用户窗口初始化
  20. Private Sub UserForm_Initialize()
  21. ActiveDocument.Unit = cdrMillimeter
  22. Dim sr As ShapeRange
  23. Dim ls, hs, lj, hj, pw, ph As Double
  24. pw = ActiveDocument.Pages.First.SizeWidth
  25. ph = ActiveDocument.Pages.First.SizeHeight
  26. TextBox1.text = 2
  27. TextBox2.text = 5
  28. TextBox3.text = 0
  29. TextBox4.text = 0
  30. Set sr = ActiveSelectionRange
  31. If sr.Count > 0 Then
  32. ls = Int(sr.SizeWidth + 0.5)
  33. hs = Int(sr.SizeHeight + 0.5)
  34. Label_Size.Caption = "尺寸: " & ls & "×" & hs & "mm"
  35. lj = Int(pw / ls)
  36. hj = Int(ph / hs)
  37. Dim jh, jl, t As Double
  38. jl = Int(pw / hs)
  39. jh = Int(ph / ls)
  40. '// Debug.Print lj, hj, jl, jh
  41. If jh * jl > hj * lj Then
  42. lj = jl
  43. hj = jh
  44. If lj * ls > pw Or hj * hs > ph Then
  45. t = lj
  46. lj = hj
  47. hj = t
  48. End If
  49. End If
  50. TextBox1.text = lj
  51. TextBox2.text = hj
  52. End If
  53. End Sub
  54. Private Sub CommandButton1_Click()
  55. On Error GoTo ErrorHandler
  56. API.BeginOpt
  57. Dim ls, hs As Integer: Dim lj, hj As Double
  58. Dim matrix As Variant: Dim sr As ShapeRange
  59. ls = Val(TextBox1.text)
  60. hs = Val(TextBox2.text)
  61. lj = Val(TextBox3.text)
  62. hj = Val(TextBox4.text)
  63. matrix = Array(ls, hs, lj, hj)
  64. Set sr = ActiveSelectionRange
  65. If ls * hs = 0 Then Exit Sub
  66. If ls = 1 Or hs = 1 Then
  67. arrange_Clone_one matrix, sr
  68. GoTo ErrorHandler
  69. End If
  70. '// 代码运行时关闭窗口刷新
  71. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  72. '// 拼版矩阵
  73. arrange_Clone matrix, sr
  74. Unload Me
  75. ErrorHandler:
  76. API.EndOpt
  77. End Sub
  78. '// 拼版矩阵 matrix = Array(ls, hs, lj, hj)
  79. Private Function arrange_Clone(matrix As Variant, sr As ShapeRange)
  80. ls = matrix(0): hs = matrix(1)
  81. lj = matrix(2): hj = matrix(3)
  82. X = sr.SizeWidth: Y = sr.SizeHeight
  83. Set s1 = sr '// Set s1 = sr.Clone
  84. '// StepAndRepeat 方法在范围内创建多个形状副本
  85. '// Set dup1 = s1.StepAndRepeat(ls - 1, x + lj, 0#)
  86. '// Set dup2 = ActiveDocument.CreateShapeRangeFromArray(dup1, s1).StepAndRepeat(hs - 1, 0#, -(Y + hj))
  87. Set dup1 = s1.StepAndRepeat(hs - 1, 0#, -(Y + hj))
  88. Set dup2 = ActiveDocument.CreateShapeRangeFromArray(dup1, s1).StepAndRepeat(ls - 1, X + lj, 0#)
  89. '// s1.Delete
  90. End Function
  91. Private Function arrange_Clone_one(matrix As Variant, sr As ShapeRange)
  92. ls = matrix(0): hs = matrix(1)
  93. lj = matrix(2): hj = matrix(3)
  94. X = sr.SizeWidth: Y = sr.SizeHeight
  95. Set s1 = sr '// Set s1 = sr.Clone
  96. '// StepAndRepeat 方法在范围内创建多个形状副本
  97. If ls > 1 Then
  98. Set dup1 = s1.StepAndRepeat(ls - 1, X + lj, 0#)
  99. Else
  100. Set dup1 = s1
  101. End If
  102. If hs > 1 Then
  103. Set dup2 = ActiveDocument.CreateShapeRangeFromArray(dup1, s1).StepAndRepeat(hs - 1, 0#, -(Y + hj))
  104. End If
  105. '// s1.Delete
  106. End Function