2012-01-26 51 views
0

我有一個Word插件,它以OpenXML格式(即.docx)寫入和讀取Word文檔。使用VBA,在Word 2003中打開擴展名不是.docx或.docm的OpenXML格式(.docx)文檔

但是,爲了能夠輕鬆識別「我的」文檔與正常的Word .docx文件相反,我使用了另一個擴展名,稱其爲.myx(或.mym用於支持宏的文檔)。

這一切在Word 2007和Word 2010中都能很好地工作,我認爲它可以在Word 2003中使用(安裝了兼容包)。

但是,Word 2003打開帶有.docx擴展名的文檔時,將不會打開.myx文檔,除非我將其重命名爲擴展名爲.docx。

當我嘗試使用VBA時,我使用了許多看起來像WdOpenFormat枚舉的明顯值,但似乎沒有任何幫助。

我真的必須將我的擴展名更改爲.docx才能讓Word 2003打開它嗎?

回答

0

答案是Office 2007的兼容包不過是Word的另一個「文本轉換器」,而.docx和.docm擴展名似乎是Word用來調用該文本轉換器的東西。

但是,這篇文章this article處理作爲.docx保存在Word 2003環境中,提供了關於如何打開文檔的提示。使用該鏈接爲指導,宏定義,這裏是你如何去尋找正確的「OpenFormat」價值開放文件的精髓(在C#):

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; 
}