繁体   English   中英

使用VBA,在Word 2003中打开扩展名不是.docx或.docm的OpenXML格式(.docx)文档

[英]Using VBA, open an OpenXML format (.docx) document in Word 2003 where the extension is not .docx or .docm

我有一个Word加载项,它以OpenXML格式(即.docx)编写和读取Word文档。

但是,为了使我可以轻松识别“我的”文档,而不是我使用另一个扩展名的普通Word .docx文件,将其称为.myx(对于启用了宏的文档,则称为.mym)。

所有这些都可以在Word 2007和Word 2010中很好地工作,我认为它可以在Word 2003中工作(安装了兼容性包)。

但是Word 2003在打开带有.docx扩展名的文档时,将不会打开.myx文档,除非我将其重命名为扩展名是.docx。

当我在VBA上进行尝试时,我使用了一些看起来很明显的WdOpenFormat枚举值,但似乎无济于事。

我是否真的必须将扩展名更改为.docx才能使用Word 2003打开它?

答案是Office 2007兼容包只是Word的另一个“文本转换器”,而.docx和.docm扩展名似乎是Word用来调用该文本转换器的工具。

但是,这篇文章这篇文章 ,这与节约作为Word 2003中的.docx环境交易,给出一个提示,如何去打开文件。 使用该链接中定义的宏作为指南,这是在C#中如何找到用于打开文档的正确“ OpenFormat”值的本质:

using MSWord = Microsoft.Office.Interop.Word;
...
private object GetOpenFormat(bool macroEnabled) {
  object result = MSWord.WdOpenFormat.wdOpenFormatAuto; /* default in case can't find the real value */
  string formatName = (macroEnabled? "Word 2007 Macro-enabled Document": "Word 2007 Document");
  foreach(MSWord.FileConverter converter in _msWordInstance.FileConverters) {
    if(string.Compare(converter.FormatName, formatName, true) == 0) {
      if(converter.CanOpen) {
        result = converter.OpenFormat;
        break;
      }
    }
  }
  return result;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM