How to obtain PowerPoint File Format Programmatically

ぐ巨炮叔叔 提交于 2019-12-18 07:11:19

问题


I need to determine whether the ActivePresentation is 97-2003 or 2007 format. I really won't want to check the extension.

Is there a property somewhere inside the PowerPoint Object Model which gives this info?


回答1:


There is no File Format property, unfortunately. You'll have to go the extention route, like:

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



回答2:


When the presentation is open there is no file format, its all in memory. However the file it came from can be in either the older binary format or the newer OpenXML format. The easiest way to tell the difference is to look at the first few bytes of the file.

For the binary formats it is an OLE Compound File which will always start with the bytes: 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1.

For the newer formats it is a ZIP file which will always start with the bytes: 0x50, 0x4B, 0x03, 0x04

Looking at the first few bytes of the file is the best way to quickly determine the file type, though it takes more work.



来源:https://stackoverflow.com/questions/2916154/how-to-obtain-powerpoint-file-format-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!