【问题标题】:PowerPoint VBA code to bring focus back to the running PowerPoint SlideshowPowerPoint VBA 代码将焦点带回正在运行的 PowerPoint 幻灯片
【发布时间】:2014-11-24 11:54:34
【问题描述】:

我有一个嵌入了 Word 文档的 PowerPoint 演示文稿。我在演示文稿上有一个宏按钮,可以打开嵌入的 word 文档,更改其中的一些内容,并将其(word)保存为 PDF 文档。但是一旦一切都完成了,当演示文稿(幻灯片)仍在后台运行时,用户会看到 powerpoint 幻灯片模式。如何将焦点带回到正在运行的幻灯片上?宏应该以幻灯片模式运行。

下面是我的代码

Private Sub Gen_Click()
    ' I am changing the presentation to normal view, in order to execute DoVerb thing!
    ActivePresentation.Windows(1).Activate

    With ActivePresentation.Slides(2).Shapes(1)

        If .Type = msoEmbeddedOLEObject Then

            For Each sVerb In .OLEFormat.ObjectVerbs

                nCount = nCount + 1

                If sVerb = "Open" Then

                    .OLEFormat.DoVerb nCount

                    Exit For

                End If

            Next

        End If

    End With

    'switch back to slide show view
    SlideShowWindows(1).Activate

'getting opened word document object to do stuff in in
    Set objWord = GetObject(, "Word.Application")
Set objDoc = objWord.ActiveDocument
objWord.Visible = False

'Doing stuff here

'closing the word doc
objDoc.Saved = True
objWord.Quit

End Sub

此代码正在使电源点返回正常模式,并带有恢复幻灯片的按钮!

【问题讨论】:

  • 您是否尝试将“SlideShowWindows(1).Activate”行移到末尾,就在 End Sub 之前?
  • 感谢您的评论!是的,我确实尝试过!如果我使用 F8 来逐个执行,效果很好!但在实际幻灯片运行时失败!我还尝试使用 SendKeys 发送 %TAB 来切换,%n 来最小化,但这些也不起作用!

标签: vba powerpoint


【解决方案1】:

终于可以使用 CommandBar 控件切换回幻灯片模式了!

在 End Sub 之前添加了以下代码

Call CommandBars.FindControl(Id:=740).Execute
    If Err.Number <> 0 Then
        MsgBox strErrorMessage
        Err.Clear
    End If
  • 740 是从功能区菜单运行幻灯片的 ID!

【讨论】:

    【解决方案2】:

    也许这也行得通,而且更简单:

    ' change focus to power point 
    AppActivate (ActivePresentation.Name)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多