admin管理员组

文章数量:1300026

I am writing a macro to delete selected slides, i.e. clicked on, in the thumbnails pane of the Normal View.

There is always a selected slide even if none have been clicked on. If the macro is run, without selecting any slides, the default slide will be deleted. Need to detect that no slides have been selected and put up a warning msg box.

ActiveWindow.Selection.SlideRange.Count returns 1, since there is always an active slide even if it's not clicked on. How do I detect that no slides are selected (clicked on) in the thumbnail pane?

Unless the user has specifically clicked between slides in the thumbnail pain of Normal view or in Slide Sorter view to select NO slides, there will always be a slide selected. So the problem becomes "How can I tell whether the user has deliberately selected a single slide or whether it just happens to be selected by default?"

Here is my code:

Sub DeleteSelectedslides()
  ActiveWindow.Selection.SlideRange.Delete
End Sub

I am writing a macro to delete selected slides, i.e. clicked on, in the thumbnails pane of the Normal View.

There is always a selected slide even if none have been clicked on. If the macro is run, without selecting any slides, the default slide will be deleted. Need to detect that no slides have been selected and put up a warning msg box.

ActiveWindow.Selection.SlideRange.Count returns 1, since there is always an active slide even if it's not clicked on. How do I detect that no slides are selected (clicked on) in the thumbnail pane?

Unless the user has specifically clicked between slides in the thumbnail pain of Normal view or in Slide Sorter view to select NO slides, there will always be a slide selected. So the problem becomes "How can I tell whether the user has deliberately selected a single slide or whether it just happens to be selected by default?"

Here is my code:

Sub DeleteSelectedslides()
  ActiveWindow.Selection.SlideRange.Delete
End Sub
Share Improve this question edited Feb 17 at 22:40 Chris 137k133 gold badges305 silver badges283 bronze badges asked Feb 11 at 15:56 Jerry VJerry V 215 bronze badges 6
  • You are talking about Powerpoint? Please select the correct tags so that we can see what your question is about. – FunThomas Commented Feb 11 at 16:04
  • Please also add the code you currently have. – Tim Williams Commented Feb 11 at 16:15
  • Current code is: – Jerry V Commented Feb 11 at 19:14
  • Sub DeleteSelectedslides() ActiveWindow.Selection.SlideRange.Delete End Sub – Jerry V Commented Feb 11 at 19:14
  • I've edited your original post to help clarify your issue. Unless you've run into it before, it's hard to understand what you're asking. I don't think there's any way to distinguish between one deliberately selected slide and the current single slide the user's looking at, so the most reliable thing might be to pop a message box asking the user "OK to delete Slide 42? _ Yes _ No" – Steve Rindsberg Commented Feb 13 at 21:12
 |  Show 1 more comment

1 Answer 1

Reset to default 0

My solution: If the active pane is not thumb nails, no slides selected.

Sub DeleteSelections()
   If ActiveWindow.Selection.SlideRange.Count = 1 Then
       If ActiveWindow.ActivePane.ViewType <> 11 Then
           MsgBox "No Slides Selected"
           End
       End If
   End If
   ActiveWindow.Selection.SlideRange.Delete
  

  'Do stuff
End Sub

本文标签: vbaMacro to delete selected slidesStack Overflow