代码之家  ›  专栏  ›  技术社区  ›  Arie Livshin

从PowerPoint 2003以编程方式另存为PowerPoint 2007(pptx)

  •  4
  • Arie Livshin  · 技术社区  · 14 年前

    我需要能够保存演示文稿(编程)在powerpoint2003作为OpenXML(“.pptx”)。 我安装了Microsoft Office兼容包。这确实允许我从powerpoint2003执行“另存为powerpoint2007演示文稿”。

    如何以编程方式执行此操作(e、 (VBA)

    Presentation.SaveAs : PpSaveAsFileType PowerPoint 2003中的枚举值 ppSaveAsOpenXMLPresentation ,我做了一个程序来打印 并发现在运行时, ppSaveAsOpenXMLPresentation = 24

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

    并得到一个“无效枚举值”异常

    你有什么办法让它工作吗?

    (PS-我知道这个问题已经有几个人在网上问过了,但是没有提供任何解决方案。)

    艾丽

    5 回复  |  直到 4 年前
        1
  •  4
  •   Community    7 年前

    编辑>一些语法

    如果兼容包启用了选项“pptx” 在“配置”对话框中,选择“默认保存格式”, 你正在试图保存另一个演示文稿 我想你可以,如果你用这样的东西:

     MyOtherPresentation.SaveAs "C:\Mypres", ppSaveAsDefault
    

    请注意,只有在演示文稿以前没有以ppt格式保存的情况下,此操作才有效

    如果上述方法不起作用,您可以尝试另一种方法。以旧格式保存文件并调用转换程序:

    ppcnvcom.exe
    here 例如(使用wordconv.exe,但基本相同)
    一定要安装所有的office升级,否则程序就会结束 没有报告错误,什么也不做。

    ofc公司
    看到了吗 here
    以及 here 好好讨论一下

        2
  •  3
  •   Dirk Vollmar    14 年前

    一个技巧是在注册表中修改应用程序的默认保存格式,然后保存,最后再次恢复原始保存格式。

    相关的关键是

    Software\Microsoft\Office\11.0\PowerPoint\Options
    

    创建 DWORD 带名称的值 DefaultFormat 并将其设置为0x21以另存为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);
                }
            }
        }       
    }
    
        3
  •  0
  •   Dudi    14 年前

    我使用了ppcnvcom.exe,但请注意,与大量帖子不同,我只使用了-oice开关,没有使用-nme开关

        4
  •  0
  •   Apsis0215    12 年前

    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
    
        5
  •  0
  •   Olle Sjögren user1810449    8 年前

    我知道这是个老问题,但我最近用了:

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

    而不是 SaveAs . 无论原稿是ppt格式还是pptx格式,都能很好地工作。

    (在不重新打开演示文稿的情况下,我无法使提到的注册表更改方法对我起作用。)

    推荐文章