VBA for Word 2010 - 将选定的形状放入视图中

时间:2015-11-17 22:11:39

标签: vba ms-word

我在MS Word 2010中使用以下VBA代码。它应该单步执行文档,找到一个形状,然后让我选择删除它。我遇到的问题是所选的形状没有显示在查看器窗口中,所以当代码询问我是否要删除它找到的形状时,我看不到那个形状。

Sub ShowShapes()
Dim myRange As Range
Dim msgTrap As VbMsgBoxResult
Dim sPrompt As String
Dim myDots As Shape
For Each myRange In ActiveDocument.StoryRanges
    Do
        For Each myDots In ActiveDocument.Shapes
                myDots.Select
                sPrompt = "Do you want to delete this?"
                msgTrap = MsgBox(sPrompt, vbYesNoCancel, "Images")
                Select Case msgTrap
                    Case vbYes
                        Selection.Delete
                    Case vbCancel
                        MsgBox "Cancel was clicked.  Exiting Routine", vbCritical, "CANCEL"
                        Exit Sub
                    'Note that Case vbNo is not listed.  That is because as the only other option
                    'the routine will proceed to End Select when vbNo is clicked.
                    End Select
        Next
        Set myRange = myRange.NextStoryRange
  Loop Until myRange Is Nothing
Next
End Sub

我尝试过使用Application.ScreenUpdating = True无效。我希望有一个我不知道的简单命令,但我无法在这里或其他地方找到答案。 TIA。

1 个答案:

答案 0 :(得分:0)

尝试:myDots.ScrollIntoView

BTW您的代码存在逻辑问题。你试图循环所有的StoryRanges是件好事。但是在下一级你查询ActiveDocument.Shapes这意味着 - 我认为,不能测试,因为我现在在移动设备上 - 你不会在你循环的StoryRange中查询形状。尝试使用myRange.ShapeRange