如何检查ActivePresentation文件类型并以MsgBox显示结果?
Perfect, since you already have the workflow down for Word and Excel, let's translate that to PowerPoint quickly:
First, a recap of what you already know:
- Word:
MsgBox ActiveDocument.SaveFormat - Excel:
MsgBox ActiveWorkbook.FileFormat
For PowerPoint, the property we use aligns with Word's approach rather than Excel's. You'll use the SaveFormat property of the ActivePresentation object. Here's the basic one-liner to display the numeric format code:
MsgBox ActivePresentation.SaveFormat
A Quick Note on the Value
That numeric value corresponds to specific PowerPoint file formats. For example:
1= PowerPoint 97-2003 (.ppt)24= Standard PowerPoint (.pptx)25= Macro-enabled PowerPoint (.pptm)32= PowerPoint Template (.potx)
If you want a more user-friendly output instead of just a number, you can wrap it in a simple Select Case block to translate the code to a readable description:
Dim formatDescription As String Select Case ActivePresentation.SaveFormat Case 1: formatDescription = "PowerPoint 97-2003 Presentation (.ppt)" Case 24: formatDescription = "PowerPoint Presentation (.pptx)" Case 25: formatDescription = "PowerPoint Macro-Enabled Presentation (.pptm)" Case 32: formatDescription = "PowerPoint Template (.potx)" Case 35: formatDescription = "PowerPoint Show (.ppsx)" ' Add additional cases for other formats you need to handle Case Else: formatDescription = "Unknown Format (Code: " & ActivePresentation.SaveFormat & ")" End Select MsgBox "Current Presentation File Format: " & formatDescription
That should give you exactly what you need—whether you want the raw format code or a clear, human-readable label.
内容的提问来源于stack exchange,提问作者Ivgeni Feldman

