UniteOne.frm 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. Option Explicit
  2. #If VBA7 Then
  3. Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  4. Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  5. #Else
  6. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  7. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  8. #End If
  9. Dim iHang, iLie, iPages As Integer '定义行数(Y) 列数(X)
  10. Dim iYouyi, iXiayi As Single '右移(R) 下移(B)
  11. 'txtHang, txtLie, txtYouyi, txtXiayi ,txtInfo
  12. Dim LogoFile As String 'Logo
  13. Dim s(1 To 255) As Shape '定义对象用于存放每页的群组
  14. Dim P As Page '定义多页
  15. '**** 主程序 执行
  16. Private Sub cmdRun_Click()
  17. '// 代码运行时关闭窗口刷新
  18. Application.Optimization = True
  19. ActiveDocument.BeginCommandGroup '一步撤消'
  20. Dim x_M, y_M
  21. ActiveDocument.Unit = cdrMillimeter
  22. ActiveDocument.EditAcrossLayers = False '跨图层编辑禁止
  23. For Each P In ActiveDocument.Pages
  24. P.Activate '激活每页
  25. P.Shapes.all.CreateSelection '每页全选
  26. Set s(P.index) = ActiveSelection.Group '存放每页的群组
  27. Next P
  28. ActiveDocument.EditAcrossLayers = True '跨图层编辑开启
  29. x_M = y_M = 0
  30. For Each P In ActiveDocument.Pages
  31. P.Activate
  32. s(P.index).MoveToLayer ActivePage.DesktopLayer '每页对象移动到桌面层
  33. s(P.index).Move (iYouyi * x_M), -(300 + iXiayi * y_M) '排列对象 右偏移,下偏移
  34. y_M = y_M + 1
  35. If y_M = iLie Then
  36. x_M = x_M + 1
  37. y_M = 0
  38. End If
  39. Next P
  40. ActiveDocument.EndCommandGroup
  41. Application.Optimization = False
  42. ActiveWindow.Refresh
  43. Application.Refresh
  44. Unload Me '执行完成关闭
  45. End Sub
  46. '**** 主程序 副本 横排序
  47. Private Sub cmdRunX_Click()
  48. '// 代码运行时关闭窗口刷新
  49. Application.Optimization = True
  50. ActiveDocument.BeginCommandGroup '一步撤消'
  51. Dim x_M, y_M
  52. ActiveDocument.Unit = cdrMillimeter
  53. ActiveDocument.EditAcrossLayers = False '跨图层编辑禁止
  54. For Each P In ActiveDocument.Pages
  55. P.Activate '激活每页
  56. P.Shapes.all.CreateSelection '每页全选
  57. Set s(P.index) = ActiveSelection.Group '存放每页的群组
  58. Next P
  59. ActiveDocument.EditAcrossLayers = True '跨图层编辑开启
  60. x_M = y_M = 0
  61. For Each P In ActiveDocument.Pages
  62. P.Activate
  63. s(P.index).MoveToLayer ActivePage.DesktopLayer '每页对象移动到桌面层
  64. s(P.index).Move (iYouyi * y_M), -(600 + iXiayi * x_M) '排列对象 右偏移,下偏移
  65. y_M = y_M + 1
  66. If y_M = iHang Then
  67. x_M = x_M + 1
  68. y_M = 0
  69. End If
  70. Next P
  71. ActiveDocument.EndCommandGroup
  72. Application.Optimization = False
  73. ActiveWindow.Refresh
  74. Application.Refresh
  75. Unload Me '执行完成关闭
  76. End Sub
  77. '*********** 初始化程序 ***************
  78. Private Sub UserForm_Initialize()
  79. Dim s As Shape
  80. ActiveDocument.Unit = cdrMillimeter '本文档单位为mm
  81. For Each P In ActiveDocument.Pages
  82. iPages = P.index
  83. If iPages = 1 Then
  84. P.Activate
  85. P.Shapes.all.CreateSelection
  86. Set s = ActiveDocument.Selection
  87. If s.Shapes.Count = 0 Then
  88. MsgBox "当前文件第一页空白没有物件!"
  89. Exit Sub
  90. End If
  91. End If
  92. Next P
  93. txtLie.text = 5
  94. txtHang.text = Int(iPages / CInt(txtLie.text) + 0.9)
  95. txtLie.text = Int(iPages / CInt(txtHang.text) + 0.9)
  96. iHang = CInt(txtHang.text)
  97. iLie = CInt(txtLie.text)
  98. iYouyi = Int(s.SizeWidth + 0.6)
  99. iXiayi = Int(s.SizeHeight + 0.6)
  100. txtYouyi.text = iYouyi
  101. txtXiayi.text = iXiayi
  102. LogoFile = Path & "GMS\262235.xyz\LOGO.jpg"
  103. If API.ExistsFile_UseFso(LogoFile) Then
  104. LogoPic.Picture = LoadPicture(LogoFile) '换LOGO图
  105. End If
  106. txtInfo.text = "本文档共 " & iPages & " 页,首页物件尺寸(mm):" & s.SizeWidth & "×" & s.SizeHeight
  107. End Sub
  108. '帮助
  109. Private Sub cmdHelp_Click()
  110. WebHelp
  111. txtInfo.text = "点击访问 https://262235.xyz 详细帮助,寻找更多的视频教程!"
  112. txtInfo.ForeColor = &HFF0000
  113. cmdHelp.Caption = "在线帮助"
  114. cmdHelp.ForeColor = &HFF0000
  115. End Sub
  116. '关闭
  117. Private Sub cmdClose_Click()
  118. Unload Me
  119. End Sub
  120. 'VB限制文本框只能输入数字和小数点
  121. Private Sub txtHang_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
  122. Dim Numbers As String
  123. Numbers = "1234567890"
  124. If InStr(Numbers, Chr(KeyAscii)) = 0 Then
  125. KeyAscii = 0
  126. End If
  127. End Sub
  128. Private Sub txtLie_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
  129. Dim Numbers As String
  130. Numbers = "1234567890"
  131. If InStr(Numbers, Chr(KeyAscii)) = 0 Then
  132. KeyAscii = 0
  133. End If
  134. End Sub
  135. Private Sub txtXiayi_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
  136. Dim Numbers As String
  137. Numbers = "1234567890" + Chr(8) + Chr(46)
  138. If InStr(Numbers, Chr(KeyAscii)) = 0 Then
  139. KeyAscii = 0
  140. End If
  141. End Sub
  142. Private Sub txtYouyi_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
  143. Dim Numbers As String
  144. Numbers = "1234567890" + Chr(8) + Chr(46)
  145. If InStr(Numbers, Chr(KeyAscii)) = 0 Then
  146. KeyAscii = 0
  147. End If
  148. End Sub
  149. Private Sub txtHang_Change()
  150. Dim n As Single
  151. n = Val(txtHang.text)
  152. If n > 0 And n < 1001 Then
  153. HangSpin.value = n
  154. iHang = n
  155. End If
  156. txtHang.text = iHang
  157. txtLie.text = Int(iPages / iHang + 0.9)
  158. iLie = CInt(txtLie.text)
  159. End Sub
  160. Private Sub HangSpin_Change()
  161. txtHang.text = CStr(HangSpin.value)
  162. End Sub
  163. Private Sub txtLie_Change()
  164. Dim n As Single
  165. n = Val(txtLie.text)
  166. If n > 0 And n < 1001 Then
  167. LieSpin.value = n
  168. iLie = n
  169. End If
  170. txtLie.text = iLie
  171. txtHang.text = Int(iPages / iLie + 0.9)
  172. iHang = CInt(txtHang.text)
  173. End Sub
  174. Private Sub LieSpin_Change()
  175. txtLie.text = CStr(LieSpin.value)
  176. End Sub
  177. Private Sub txtXiayi_Change()
  178. Dim n As Single
  179. n = Val(txtXiayi.text)
  180. If n > 0 And n < 1001 Then
  181. iXiayi = n
  182. End If
  183. End Sub
  184. Private Sub txtYouyi_Change()
  185. Dim n As Single
  186. n = Val(txtYouyi.text)
  187. If n > 0 And n < 1001 Then
  188. iYouyi = n
  189. End If
  190. End Sub
  191. Function WebHelp()
  192. Dim h As Long, r As Long
  193. If cmdHelp.Caption = "在线帮助" Then
  194. h = FindWindow(vbNullString, "CorelDRAW 合并多页为一页 蘭雅sRGB 2010-2022")
  195. r = ShellExecute(h, "", "https://262235.xyz/index.php/tag/vba/", "", "", 1)
  196. End If
  197. End Function