检查ActivePresentation文件类型

时间:2018-04-12 12:11:11

标签: powerpoint powerpoint-vba

如何检查ActivePresentation文件类型并使用msgbox显示?

我知道如何在Word和Excel中执行此操作 -

Word:msgbox activedocument.SaveFormat

Excel:msgbox ActiveWorkbook.FileFormat

由于

1 个答案:

答案 0 :(得分:0)

我认为PowerPoint中没有任何等效的FileFormat / SaveFormat属性,因此您可能需要查看该文件的扩展名。

这样的事情:

Option Explicit

Sub Test()
    MsgBox FileType(ActivePresentation.Name)

End Sub

Function FileType(sName As String) As String

    Dim sMsg As String
    Dim sExt As String

    If InStr(sName, ".") = 0 Then
        sMsg = "File hasn't been saved, so type is unknown."
    Else
        sExt = Mid$(sName, InStrRev(sName, ".") + 1)
        Select Case UCase(sExt)
            Case Is = "PPT"
                sMsg = "Powerpoint 2003 or earlier"
            Case Is = "PPTX"
                sMsg = "Powerpoint 2007 or later"
            Case Is = "PPTM"
                sMsg = "Powerpoint 2007 or later, with macros"
            Case Is = "PPS"
                sMsg = "Powerpoint 2003 or earlier SHOW file"
            Case Is = "PPSX"
                sMsg = "Powerpoint 2007 or later SHOW file"
            Case Is = "PPSM"
                sMsg = "Powerpoint 2007 or later SHOW file with macros"

            ' Add more case statements as needed

            Case Else
                sMsg = "Unknown file type (" & sExt & ")"
        End Select
    End If

    FileType = sMsg

End Function