如何以编程方式获取PowerPoint文件格式

时间:2010-05-26 19:34:49

标签: ms-office powerpoint office-interop powerpoint-vba

我需要确定ActivePresentation是97-2003还是2007格式。我真的不想检查扩展名。

PowerPoint对象模型中是否有某个属性可以提供此信息?

2 个答案:

答案 0 :(得分:3)

当演示文稿打开时,没有文件格式,它全部在内存中。但是,它来自的文件可以是较旧的binary format或较新的OpenXML format。区分差异的最简单方法是查看文件的前几个字节。

对于二进制格式,它是OLE Compound File,它始终以字节开头:0xD0,0xCF,0x11,0xE0,0xA1,0xB1,0x1A,0xE1。

对于较新的格式,它是ZIP file,它始终以字节开头:0x50,0x4B,0x03,0x04

查看文件的前几个字节是快速确定文件类型的最佳方法,但需要更多工作。

答案 1 :(得分:0)

遗憾的是,没有文件格式属性。你必须走延伸路线,如:

Sub APFileFormat()
Dim ap As Presentation
Set ap = ActivePresentation
Length = Len(ap.Name)
Match = InStrRev(StringCheck:=ap.Name, StringMatch:=".")
ExtentionLength = Length - Match
    Select Case ExtentionLength
        Case 4
            FileFormat = "PowerPoint 2007-2010"
        Case 3
            FileFormat = "PowerPoint 97-2003"
        Case Else
            FileFormat = "undetermined"
    End Select
Debug.Print "The file format of the active presentation is " & FileFormat
End Sub