【发布时间】:2011-02-24 08:39:53
【问题描述】:
我需要确定ActivePresentation 是97-2003 还是2007 格式。我真的不想检查扩展程序。
PowerPoint 对象模型中是否有提供此信息的属性?
【问题讨论】:
标签: vba ms-office powerpoint office-interop
我需要确定ActivePresentation 是97-2003 还是2007 格式。我真的不想检查扩展程序。
PowerPoint 对象模型中是否有提供此信息的属性?
【问题讨论】:
标签: vba ms-office powerpoint office-interop
当演示文稿打开时,没有文件格式,所有文件都在内存中。但是,它来自的文件可以是较旧的binary format 或较新的OpenXML format。最简单的区分方法是查看文件的前几个字节。
对于二进制格式,它是一个OLE Compound File,它总是以字节开头:0xD0、0xCF、0x11、0xE0、0xA1、0xB1、0x1A、0xE1。
对于较新的格式,它是 ZIP file,它将始终以字节开头:0x50、0x4B、0x03、0x04
查看文件的前几个字节是快速确定文件类型的最佳方法,尽管它需要更多的工作。
【讨论】:
不幸的是,没有文件格式属性。您必须走扩展路线,例如:
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
【讨论】: