在没有激活的情况下设置放大PowerPoint文档窗口

我正在创build一个Excel-VBA文件的PPT,并希望将ppt的缩放设置为100%。

我怎样才能从Excel文件做到这一点,而无需激活PowerPoint窗口?
或者我甚至可以通过激活窗口来做到这一点?

以下Excel示例代码在桌面上打开一个PPT文件,并尝试设置这个PPT的缩放,但它似乎不工作:

Sub CreatePptAndSetZoom() Dim ppApp As PowerPoint.Application Dim ppPres As PowerPoint.Presentation Dim strTemplate$ 'Look for existing instance of PPT On Error Resume Next Set ppApp = GetObject(, "PowerPoint.Application") On Error GoTo 0 'Create new instance of PPT if no instance exists If ppApp Is Nothing Then Set ppApp = New PowerPoint.Application 'Define Path of Template and open new ppt strTemplate = Environ("UserProfile") & "\Desktop\Test.pptx" Set ppPres = ppApp.presentations.Open(strTemplate, False, True, True) 'Set Zoom ppApp.ActiveWindow.View.Zoom = 100 End Sub 

在Excel文件中设置从Excel文件中的缩放使用略有不同的语句(没有View ):

 Application.ActiveWindow.Zoom = 100 

有没有人知道如何解决这个问题没有任何代码在PPT文件?

有一些帮助(谢谢R3uK!)我发现了以下解决scheme基于问题中的最后一个代码:

解:

而不是ppApp.ActiveWindow.View.Zoom = 100使用以下内容:

ppPres.Windows(1).Panes(2).Activate – >激活主幻灯片窗格
ppPres.Windows(1).View.Zoom = 100 – >在窗口中设置活动窗格的缩放ppPres.Windows(1).View.Zoom = 100

一些评论:

ppPres.Windows(1) – >仅收集演示文稿所在的窗口集合

ppApp.Windows(1) – >收集所有打开的PPT窗口。 因此,如果在第1项之前打开了一个ppt,则不会返回正确的窗口。

ppPres.Windows(1).Panes(2) – > ppt窗口内的窗格集合在我的情况下,依赖于项目编号的以下ViewTypes:

第1项: ppViewThumbnails (左侧的小型幻灯片)
第2项: ppViewSlide (主视图)
项目3: ppViewNotesPage (底部的评论部分)

所以在我的例子中,我想改变项目2的主幻灯片视图窗格的缩放。

您的代码运行使用迟交:

 Sub ZoomInPptFromExcel() Dim ppApp As Object 'Get existing instance of PPT On Error Resume Next Set ppApp = GetObject(, "PowerPoint.Application") On Error GoTo 0 'Set Zoom ppApp.ActiveWindow.View.Zoom = 100 End Sub 

 Sub CreatePptAndSetZoom() Dim ppApp As Object 'PowerPoint.Application Dim ppPres As Object 'PowerPoint.Presentation Dim strTemplate$ 'Look for existing instance of PPT On Error Resume Next Set ppApp = GetObject(, "PowerPoint.Application") On Error GoTo 0 'Create new instance of PPT if no instance exists If ppApp Is Nothing Then Set ppApp = CreateObject("PowerPoint.Application") 'Define Path of Template and open new ppt strTemplate = Environ("UserProfile") & "\Desktop\Test.pptx" Set ppPres = ppApp.Presentations.Open(strTemplate, False, True, True) 'Set ppPres = ppApp.Presentations.Add 'Set Zoom ppApp.ActiveWindow.View.Zoom = 100 End Sub