通过 VBA (Excel) 关闭一个 PPT 演示文稿
Closing one single PPT Presentation via VBA (Excel)
我想在Excel中通过VBA关闭PPT。问题在于代码 "PP.Close"。 (最后一行代码)
- 它还会关闭其他打开的 PPT 演示文稿,而不仅仅是我 "target"
- 有时它会关闭演示文稿和应用程序,有时只会关闭演示文稿,我认为这很奇怪。
有人知道我该如何解决这些问题吗?
谨致问候并提前致谢
Sub Saveas_PPT()
Dim PP As PowerPoint.Presentation
Dim Sl As PowerPoint.Slide
Dim sh As Variant
Dim company As String
'Dim ws_company As Worksheet
Set Dropdown.ws_company = Tabelle2
company = Dropdown.ws_company.Range("C2").Value
Dim strPOTX As String
Dim strPfad As String
Dim pptApp As Object
strPfad = "C:\Users\Michael\" 'Ordner der Vorlage
strPOTX = "Test.pptx" 'Hier theoretisch auch
filepicker möglich
Set pptApp = New PowerPoint.Application
Dim pptVorlage As String
pptVorlage = strPfad & strPOTX
Set PP = pptApp.Presentations.Open(pptVorlage)
pptApp.ActivePresentation.UpdateLinks
' Dim x As Integer
' For Each prs In PP.Application.Presentations
'
' x = x + 1
'
'If x > 1 Then
''pptApp.ActivePresentation.Close ' Hier auch
' 'PP.Close 'Problem: Hier wird alles geschlossen
' Exit Sub
'End If
' Next prs
'pp.Application.Quit 'vorher FUnktion die schaut ob mehr als eine PPT offen sind. Wenn nur eine dann quit, sonst nur diese hier schließen
pp.Close
End Sub
我的建议是使用AppActivate函数。
需要window的标题。
我不确定它是否有效,但至少会激活正确的演示文稿。
AppActivate("the PowerPoint title")
将 the PowerPoint title
替换为 Windows 标题。
你可以,如果也失败了,也许可以在它之后使用 sendkeys 到 ALT + F4 来关闭活动 window,这应该是你想要的演示文稿。
我想在Excel中通过VBA关闭PPT。问题在于代码 "PP.Close"。 (最后一行代码)
- 它还会关闭其他打开的 PPT 演示文稿,而不仅仅是我 "target"
- 有时它会关闭演示文稿和应用程序,有时只会关闭演示文稿,我认为这很奇怪。
有人知道我该如何解决这些问题吗?
谨致问候并提前致谢
Sub Saveas_PPT()
Dim PP As PowerPoint.Presentation
Dim Sl As PowerPoint.Slide
Dim sh As Variant
Dim company As String
'Dim ws_company As Worksheet
Set Dropdown.ws_company = Tabelle2
company = Dropdown.ws_company.Range("C2").Value
Dim strPOTX As String
Dim strPfad As String
Dim pptApp As Object
strPfad = "C:\Users\Michael\" 'Ordner der Vorlage
strPOTX = "Test.pptx" 'Hier theoretisch auch
filepicker möglich
Set pptApp = New PowerPoint.Application
Dim pptVorlage As String
pptVorlage = strPfad & strPOTX
Set PP = pptApp.Presentations.Open(pptVorlage)
pptApp.ActivePresentation.UpdateLinks
' Dim x As Integer
' For Each prs In PP.Application.Presentations
'
' x = x + 1
'
'If x > 1 Then
''pptApp.ActivePresentation.Close ' Hier auch
' 'PP.Close 'Problem: Hier wird alles geschlossen
' Exit Sub
'End If
' Next prs
'pp.Application.Quit 'vorher FUnktion die schaut ob mehr als eine PPT offen sind. Wenn nur eine dann quit, sonst nur diese hier schließen
pp.Close
End Sub
我的建议是使用AppActivate函数。
需要window的标题。
我不确定它是否有效,但至少会激活正确的演示文稿。
AppActivate("the PowerPoint title")
将 the PowerPoint title
替换为 Windows 标题。
你可以,如果也失败了,也许可以在它之后使用 sendkeys 到 ALT + F4 来关闭活动 window,这应该是你想要的演示文稿。