2014-09-30 125 views
0

我有一个带有嵌入式Word文档的PowerPoint演示文稿。我在演示文稿上有一个宏按钮,用于打开嵌入的Word文档,更改某些内容,并将它作为PDF文档保存(单词)。但是一旦完成,用户将显示幻灯片模式,而演示文稿(幻灯片)仍在后台运行。我如何将焦点带回到正在运行的幻灯片?该宏应该以幻灯片模式运行。PowerPoint VBA代码将焦点带回运行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 

该代码使得功率点返回到正常模式按钮恢复幻灯片!

+0

您是否尝试过移动“SlideShowWindows(1).Activate”行到最后,就这样结束前分? – 2014-09-30 14:39:09

+0

感谢您的评论!是的,我尝试过!如果我们使用F8来逐步执行,那么它工作得很好!但在实际幻灯片播放时失败!我也尝试使用SendKeys发送%TAB切换,%n最小化,但这些都不起作用! – 2014-09-30 23:33:18

回答

0

终于得到它使用CommandBar控件切换回幻灯片模式!

添加以下代码结束前分

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

也许这个工程,以及和更简单:

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