4
votes

I need to be able to save Presentations (programatically) in PowerPoint 2003 as OpenXML (".pptx"). I installed the Microsoft Office Compatibility Pack. This indeed allows me to perform "Save as PowerPoint 2007 Presentation" from PowerPoint 2003.

How can I do this programmatically? (e.g. VBA)

I tried Presentation.SaveAs: While there is no inherent PpSaveAsFileType enum value in PowerPoint 2003 for ppSaveAsOpenXMLPresentation, I made a program which prints the PpSaveAsFileType values and found out that during run-time, ppSaveAsOpenXMLPresentation = 24.

However, I tried: SaveAs(@"c:\temp\saveas\pupik.pptx", (PpSaveAsFileType) ((int) 24), MsoTriState.msoTrue);

And got an "Invalid Enumeration Value" Exception

Any ideas how to make this work?

(PS - I am aware that this question was already asked by several people on the web, but no solutions were offered.)

Thanks, Arie

5

5 Answers

4
votes

Edit > Some grammar

AFAIK the pptx format does not support macro-enabled presentations, so if your code is in the presentation you are trying to save, it will not work.

I don't have Excel 2003 at hand now, but if the Compatibility Pack enabled the option "pptx" in the Configuration Dialog, Default Save Format, and you are trying to save ANOTHER presentation I guess you can if you use something like:

 MyOtherPresentation.SaveAs "C:\Mypres", ppSaveAsDefault

Please note that this may work only if the presentation had not been saved before in ppt format

EDIT

If the above doesn't work, you could try a different approach. Save the file in the old format and the call a conversion program:

ppcnvcom.exe
See here for an example (using wordconv.exe, but essentially the same)
Be sure to have all the office upgrades installed, because if not the program ends reporting no error and doing nothing.

ofc
See here for instructions
And here for a good discussion

HTH!

3
votes

A trick is to modify the default save format of the application in the Registry, then save and finally to restore the original save format again.

The relevant key is

Software\Microsoft\Office\11.0\PowerPoint\Options

Create a DWORD value with name DefaultFormat and set it to 0x21 to save as PPTX.

public void SomeMethod()
{
    ...
    using (PptxSaver pptxSaver = new PptxSaver())
    {
        presentation.SaveAs("sample.pptx")
    }
    ...
}

class PptxSaver : IDisposable
{
    private const string OptionKey = @"Software\Microsoft\Office\11.0\PowerPoint\Options";
    private const string OptionValue = "DefaultFormat";        
    private const int SaveFormatPptx = 0x21;

    private int oldFormat;

    public PptxSaver()
    {
        using (RegistryKey key = Registry.CurrentUser.OpenSubKey(OptionKey, true))
        {
            oldFormat = (int)key.GetValue(OptionValue, -1);
            key.SetValue(OptionValue, SaveFormatPptx, RegistryValueKind.DWord);
        }
    }

    public void Dispose()
    {
        // Delete the value
        using (RegistryKey key = Registry.CurrentUser.OpenSubKey(OptionKey, true))
        {
            if (oldFormat == -1)
            {
                key.DeleteValue(OptionValue);
            }
            else
            {
                key.SetValue(OptionValue, oldFormat);
            }
        }
    }       
}
0
votes

I used ppcnvcom.exe but note that unlike a considerable amount of posts I used only the -oice switch without the -nme switch

0
votes

For VBA this works:

Sub TestSaveas()
  SaveAs "c:\somefilepath\"
End sub

Private Sub SaveAs(fp As String)
   Dim dlgSaveAs As FileDialog
   Dim strMyFile As String

   Set dlgSaveAs = Application.FileDialog(msoFileDialogSaveAs)
   With dlgSaveAs
       .InitialFileName = fp
       If .Show = -1 Then
           strMyFile = .SelectedItems(1)
           Application.ActivePresentation.SaveAs strMyFile
           'MsgBox strMyFile
           ''-- save your file to strMyFile here
       Else
           MsgBox "File not saved"
       End If
   End With
   dlgSaveAs.Execute
   Set dlgSaveAs = Nothing
End Sub
0
votes

I know this is an old question, but I got around the problem recently using:

Presentation.SaveCopyAs "c:\temp\saveas\pupik.pptx"

instead of SaveAs. Works well, regardless wether the original is in ppt- or pptx-format.

(I could not get the registry-change method mentioned to work for me without reopening the presentation.)