PowerPoint - 确定光标是在第一张幻灯片之前还是之后
我需要确定 PowerPoint 幻灯片窗格中的光标位置,以便在正确的位置插入新幻灯片。
当选择幻灯片时,当前幻灯片编号为Application.ActiveWindow.View.Slide.SlideIndex。 当光标位于幻灯片之间时,切换到另一个视图然后返回(例如,切换到幻灯片视图,然后返回幻灯片排序器)会选择光标之前的幻灯片,然后上述方法将起作用。
问题出在一种情况下:当光标位于第一张幻灯片之前或之后时。在这两种情况下,来回切换视图都会将光标定位在第一张幻灯片上。
如何确定幻灯片窗格中的光标位置是在第一张幻灯片之前还是之后?
I need to determine the cursor position in the slide-pane in PowerPoint, in order to insert a new slide in the correct position.
When a slide is selected, the current slide number is Application.ActiveWindow.View.Slide.SlideIndex.
When the cursor is between slides, switching to another view and then back (e.g., to Slide View and then back to Slide Sorter) selects the slide immediately before the cursor, and then the method above works.
The problem is in one case: when the cursor is positioned before the first slide or after it. Switching the view back and forth, positions the cursor on the first slide in both cases.
How can I determine if the cursor position in the Slide-Pane is before the first slide or after it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好问题。
一种丑陋的方法是使用 SendKeys 来喷射向下箭头键。如果光标位于第一张幻灯片上方,则会导致选择第一张幻灯片。如果光标位于第一张幻灯片和第二张幻灯片之间,则将选择第二张幻灯片。
稍微不那么难看的是使用 .Execute 方法来触发插入新幻灯片的正确控件,这应该模仿用户在执行相同操作时所得到的结果;如果插入的幻灯片的索引为 1,则光标位于原始第一张幻灯片的上方。如果插入的幻灯片的索引为 2,则光标最初位于幻灯片 1 和 2 之间。
或者使用 SendKeys ("^M") 来完成相同的操作(在 IDE 中不起作用,但在 PPT 中,您可以 Alt +F8 并选择宏来运行它。)
例如:如果光标位于第一张幻灯片上方,则显示 1;如果光标位于幻灯片 1 和 2 之间,则显示 2。DoEvnts 是必要的;否则,PPT 在下一行运行之前尚未创建幻灯片,并且会出错。
我怀疑您想要添加一些安全检查,以确保现有幻灯片(而不是您刚刚插入的幻灯片)不会被错误删除。
Good question.
One ugly method would be to use SendKeys to squirt a downarrow key. If the cursor's above the first slide, that will cause the first slide to be selected. If the cursor's between slides one and two, then the second slide will be selected.
Slightly less ugly would be to use the .Execute method to fire off the correct control for inserting a new slide, which should mimic what the user gets when they do the same thing; if the inserted slide's index is 1, then the cursor was above the original first slide. If the inserted slide's index is 2, the cursor was originally between slides 1 and 2.
Or use SendKeys ("^M") to accomplish the same thing (won't work from w/in the IDE but in PPT proper you can Alt+F8 and choose the macro to run it.)
Ex: this displays 1 if the cursor was above the first slide, 2 if it was between slides 1 and 2. The DoEvnts is necessary; otherwise PPT hasn't created the slide before the next line runs and it errors out.
I suspect you'd want to add some safety checks to make sure that an existing slide doesn't get mistakenly deleted rather than the one you've just inserted.
同意,SendKeys 不好,执行起来更安全,但仍然有点风险。
您可以迭代窗格集合并检查活动窗格的 ViewType,而无需更改活动窗格或用户的选择点。如果 ViewType = 11,则选择点位于缩略图窗格中(然后您需要执行“插入虚拟幻灯片”技巧来确定它在缩略图窗格中的确切位置)。
注意:如果您从 PPT 中运行此程序,则必须使用 Alt+F8 来启动它。使用菜单栏/功能区选项卡会将焦点从用户选择的窗格移开,并为您提供虚假结果。
Agreed, SendKeys is bad, .Execute safer but still a bit risky.
You can iterate the panes collection and check the ViewType of the active pane w/o changing the active pane or the user's selection point. If the ViewType = 11, the selection point's in the thumbnails pane (and then you'd want to do the Insert Dummy Slide trick to figure out exactly where in the thumbnails pane it is).
Note: if you run this from within PPT, you have to use Alt+F8 to launch it. Using the menu bar/ribbon tab will move the focus away from the user-selected pane and give you bogus results.