vba - 如何检查 PowerPoint 文件是否打开?

标签 vba ms-word powerpoint

我正在尝试创建一个 MS Word 宏来检查特定的 powerpoint 文件是否打开。如果是,那么我希望它转到下一个,但如果不是,则打开文件。

Public Sub CommandButton1_Click()
Dim pptApp As Object
Dim pptPres As String
'Dim nSlide As PowerPoint.Presentation
Dim folderPath, file As String

folderPath = ActiveDocument.Path & Application.PathSeparator
file = "Huntington_Template.pptx"

Set pptApp = CreateObject("PowerPoint.Application")

If pptApp.presentations(file).Enabled = True Then
    GoTo cont
Else
    pptApp.Visible = True
    pptApp.presentations.Open (folderPath & file)
End If

续:

End Sub

最佳答案

Steve 代码的一个小变体,以防您不仅要测试演示文稿是否打开,还要直接使用它:

Function GetPowerpointFileIfOpen(pptApp As Object, sFullname As String) As Object
    For Each p In pptApp.Presentations
        If p.FullName = sFullname Then
            Set GetPowerpointFileIfOpen = p
            Exit Function
        End If
    Next p
End Function

然后您可以测试演示文稿是否打开 - 或者以其他方式打开它:

Set ppt = GetPowerpointFileIfOpen(pptApp, sFullName)
If ppt Is Nothing Then
    Set ppt = pptApp.Presentations.Open(sFullName, False)
End If

关于vba - 如何检查 PowerPoint 文件是否打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24637429/

相关文章:

html - 从网页中提取可能未格式化为表格的数据

vba - Excel VBA : Creating "fall through" in nested if-else statements, 并且还允许正常行为?

vba - VB中的 "&[Page]"是什么变量?

vba - PowerPoint VBA - 在关闭时保留自定义 CommandBar 设置

webforms - 从 MS Word 文档粘贴到 Web 表单

javascript - 使用 JavaScript 创建 OpenXML 文档

linux - 如何在 Linux 上将 pptx 文件转换为 jpg 或 png(对于每张幻灯片)?

php - 如何在 PHP 中阅读 Word、Excel 和 PDF 文档?

c# - 如何从word文档中读取合并的单元格

delphi - 将 PowerPoint VBA 代码转换为 Delphi, "keep source formatting"问题