Replace_UI.bas 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  2. Dim pos_x As Variant
  3. Dim pos_Y As Variant
  4. pos_x = Array(307, 27)
  5. pos_Y = Array(64, 126, 188, 200)
  6. If Abs(X - pos_x(0)) < 30 And Abs(Y - pos_Y(0)) < 30 Then
  7. Call copy_shape_replace
  8. ElseIf Abs(X - pos_x(0)) < 30 And Abs(Y - pos_Y(1)) < 30 Then
  9. Call copy_shape_replace_resize
  10. ElseIf Abs(X - pos_x(0)) < 30 And Abs(Y - pos_Y(2)) < 30 Then
  11. Call image_replace
  12. ElseIf Abs(X - pos_x(1)) < 30 And Abs(Y - pos_Y(3)) < 30 Then
  13. CorelVBA.WebHelp "https://262235.xyz/index.php/tag/vba/"
  14. End If
  15. Replace_UI.Hide
  16. End Sub
  17. Private Sub image_replace()
  18. On Error GoTo ErrorHandler
  19. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  20. Dim image_path As String
  21. image_path = API.GetClipBoardString
  22. ActiveDocument.ReferencePoint = cdrCenter
  23. Dim sh As Shape, shs As Shapes, cs As Shape
  24. Dim X As Double, Y As Double
  25. Set shs = ActiveSelection.Shapes
  26. cnt = 0
  27. For Each sh In shs
  28. If cnt = 0 Then
  29. ActiveDocument.ClearSelection
  30. ActiveLayer.Import image_path
  31. Set sc = ActiveSelection
  32. cnt = 1
  33. Else
  34. sc.Duplicate 0, 0
  35. End If
  36. sh.GetPosition X, Y
  37. sc.SetPosition X, Y
  38. sh.GetSize X, Y
  39. sc.SetSize X, Y
  40. sh.Delete
  41. Next sh
  42. '// 代码操作结束恢复窗口刷新
  43. ActiveDocument.EndCommandGroup
  44. Application.Optimization = False
  45. ActiveWindow.Refresh: Application.Refresh
  46. Exit Sub
  47. ErrorHandler:
  48. MsgBox "请先复制图片的完整路径,本工具能自动替换图片!"
  49. Application.Optimization = False
  50. On Error Resume Next
  51. End Sub
  52. Private Sub copy_shape_replace_resize()
  53. On Error GoTo ErrorHandler
  54. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  55. ActiveDocument.ReferencePoint = cdrCenter
  56. Dim sh As Shape, shs As Shapes, cs As Shape
  57. Dim X As Double, Y As Double
  58. Set shs = ActiveSelection.Shapes
  59. cnt = 0
  60. For Each sh In shs
  61. If cnt = 0 Then
  62. Set sc = ActiveDocument.ActiveLayer.Paste
  63. cnt = 1
  64. Else
  65. sc.Duplicate 0, 0
  66. End If
  67. sh.GetPosition X, Y
  68. sc.SetPosition X, Y
  69. sh.GetSize X, Y
  70. sc.SetSize X, Y
  71. sh.Delete
  72. Next sh
  73. '// 代码操作结束恢复窗口刷新
  74. ActiveDocument.EndCommandGroup
  75. Application.Optimization = False
  76. ActiveWindow.Refresh: Application.Refresh
  77. Exit Sub
  78. ErrorHandler:
  79. MsgBox "请先复制Ctrl+C,然后选择要替换的物件运行本工具!"
  80. Application.Optimization = False
  81. On Error Resume Next
  82. End Sub
  83. Private Sub copy_shape_replace()
  84. On Error GoTo ErrorHandler
  85. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  86. ActiveDocument.ReferencePoint = cdrCenter
  87. Dim sh As Shape, shs As Shapes, cs As Shape
  88. Dim X As Double, Y As Double
  89. Set shs = ActiveSelection.Shapes
  90. cnt = 0
  91. For Each sh In shs
  92. If cnt = 0 Then
  93. Set sc = ActiveDocument.ActiveLayer.Paste
  94. cnt = 1
  95. Else
  96. sc.Duplicate 0, 0
  97. End If
  98. sh.GetPosition X, Y
  99. sc.SetPosition X, Y
  100. sh.Delete
  101. Next sh
  102. '// 代码操作结束恢复窗口刷新
  103. ActiveDocument.EndCommandGroup
  104. Application.Optimization = False
  105. ActiveWindow.Refresh: Application.Refresh
  106. Exit Sub
  107. ErrorHandler:
  108. MsgBox "请先复制Ctrl+C,然后选择要替换的物件运行本工具!"
  109. Application.Optimization = False
  110. On Error Resume Next
  111. End Sub