开发者

How do I find out the file format of a presentation in PowerPoint VSTO?

I have been working on some Office add-ins for the 2007 Office System. The add-ins need to know the file format as they are only to perform their actions when the format is one of the newer compressed XML-based formats (docx, xlsx, xlsm, pptx, etc.).

Despite the disparity in the APIs (calls and behaviours) for each Office product, I have managed to produce working add-ins for Word and Excel. In both of these, I can detect the save event and make my changes based on the file format and whether it is a save or save as operation. However, I have come to PowerPoint and I am struggling to determine what format the file is or is being saved as and whether it is a regular save or a save as operation.

So, my questions are,开发者_JS百科 in a PowerPoint VSTO add-in:

  • Is there any way to determine the file format (other than just a file extension comparison)?
  • Is it possible to determine if a save is a regular save or a save as?

Update

Okay, I changed my search and found these questions that seem to answer my first question (i.e. there is no way other than to use the extension), but the second question still stands (perhaps until I improve my search-fu).

  • How to obtain PowerPoint File Format Programmatically
  • How can I get the ActivePresentation file format from PowerPoint Interop


As I recall with PPT, there's no way to do it. You have to intercept the OPEN event, cache the file name for the document, then, during the save, check the filename. if its the same, then it was a SAVE, If different, it's a save as.

If the document was NEW, there won't be an initial filename, so the save would HAVE to be a save as.


Application.PresentationBeforeSave is the event to hook that will tell you this is a "Save As..." because it occurs right before the Save As dialog appears. Application.PresentationSave is a regular save (but can be used for a "Save As..." programatically)

So what I would do is put a global variable of something like Dim isSaveAs As Boolean = False in the module, then in Application.PresentationBeforeSave set it to True (unless its argument of Cancel = True - in that case I would set it back to False). Then in the Application.PresentationSave event I would check for If isSaveAs = True Then DoThis Else DoThat. Then set isSaveAs back to False at the end of the Application.PresentationSave event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜