在VBA for Microsoft Word中,我正在尝试编写一个子程序,它将搜索文档中的所有形状,找到文本框中的形状,并通过剪切和粘贴将它们移动到新创建的文档中。
我的问题是sub只会将找到的第一个文本框移动到新文档。如果我再次运行它将移动下一个,等等。有没有办法可以选择多个文本框,类似于普通word文档中存在的Shift-Left_Click功能?我将在下面发布我的代码:
Option Explicit
Public shp As Shape
Public Count As Integer
Public OldDoc As String
Public NewDoc As String
Sub BringTextBoxesToDoc()
Dim Count As Integer
Dim i As Integer
Count = 0
OldDoc = ActiveDocument.Name
Documents.Add
ActiveDocument.ActiveWindow.Caption = "Comment Textboxes"
NewDoc = ActiveDocument.Name
Documents(OldDoc).Activate
For Each shp In ActiveDocument.Shapes
If shp.Type = msoTextBox Then
Count = Count + 1
shp.Name = "Textbox" & Count
shp.Select
With Selection
.Cut
End With
Documents(NewDoc).Activate
Selection.Paste
End If
Next shp
End Sub