PowerPoint VBA代码将焦点带回正在运行的PowerPoint幻灯片

时间:2014-09-30 00:27:48

标签: vba powerpoint-vba

我有一个带有嵌入式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

此代码通过按钮恢复幻灯片显示使电源点返回正常模式!

2 个答案:

答案 0 :(得分:0)

最后让它使用CommandBar控件切换回幻灯片模式!

在End Sub

之前添加了以下代码
Call CommandBars.FindControl(Id:=740).Execute
    If Err.Number <> 0 Then
        MsgBox strErrorMessage
        Err.Clear
    End If
  • 740是从功能区菜单运行幻灯片显示的ID!

答案 1 :(得分:0)

也许这样做也很简单:

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