先建立一个子程序,开启一个MsgBox对话框,1 2 3 三个分支,太懒了,直接使用 是(Y) 否(N) 取消,不想自己实现对话框,直接用 MsgBox对话框
Sub 剪贴板物件替换()
xz = MsgBox("使剪贴板上的物件替换选择的目标物件" & vbNewLine & vbNewLine & "点击 是(Y) 直接替换目标" & vbNewLine & _
"点击 否(N) 调整尺寸和目标一样大小" & vbNewLine & "点击 取消 实际自动图片替换功能!", _
vbYesNoCancel, "用剪贴板上的物件替换对象")
If xz = vbYes Then
Call copy_shape_replace
ElseIf xz = vbNo Then
Call copy_shape_replace_resize
ElseIf xz = vbCancel Then
Call image_replace
End If
End Sub
源码很简单,这个是直接替换的 copy_shape_replace 分支,其他两个按这个样子,再画2个葫芦就可以了
Private Sub copy_shape_replace()
ActiveDocument.ReferencePoint = cdrCenter
Dim sh As Shape, shs As Shapes, cs As Shape
Dim x As Double, y As Double
Set shs = ActiveSelection.Shapes
cnt = 0
For Each sh In shs
If cnt = 0 Then
Set sc = ActiveDocument.ActiveLayer.Paste
cnt = 1
Else
sc.Duplicate 0, 0
End If
sh.GetPosition x, y
sc.SetPosition x, y
sh.Delete
Next sh
End Sub
0 条评论