我從Excel-VBA文件創建PPT,並且想要將PPT的縮放設置爲100%。設置在不激活的情況下放大PowerPoint文檔窗口
如何在不激活PowerPoint窗口的情況下從Excel文件執行此操作?
或者我怎麼才能通過激活窗口來做到這一點?
在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文件的任何代碼解決這個問題?
謝謝你的回答。但我認爲這與晚期或早期的約束無關。當我打開一個新的ppt,然後運行代碼時,它同時適用於遲到和早期綁定。看來,當我嘗試設置我的VBA創建的ppt文件的縮放時,這兩個代碼只會出現自動化錯誤。 – JackTheFruit
@JackTheFruit:該應用是否可見?請修改您的帖子以提供完整的代碼,以便我們可以看到您正在做什麼。 – R3uK
@JackTheFruit:我編輯了我的帖子以包含代碼的工作版本,我還用'Set ppPres = ppApp.Presentations.Add'對其進行了測試,並且這兩種情況對我來說都很好。 – R3uK