UniteOne.bas 7.2 KB

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