2012-03-28 33 views
5

我開發了一個帶有Office 2010 Professional Installed的VB.Net(VS2010)的WinForm應用程序,它是64位Windows 7平臺。該程序將打開一個.doc和.rtf格式的文檔,並嘗試將其保存爲htm格式。我使用下面的命令:SaveAs2對於Word 2010,不能與具有Word 2007的客戶端PC一起使用

昏暗sFilePath作爲字符串=「C:\ ABC \ FILE.DOC」

 Dim oApp As New Microsoft.Office.Interop.Word.Application 
     Dim oDoc As New Microsoft.Office.Interop.Word.Document 
     Dim sTempFileName As String = System.IO.Path.GetTempFileName() 
     oDoc = oApp.Documents.Open(sFilePath) 
     oApp.Visible = False 
     oDoc = oApp.ActiveDocument 
     oDoc.SaveAs2(sTempFileName, FileFormat:=WdSaveFormat.wdFormatHTML,CompatibilityMode:=Microsoft.Office.Interop.Word.WdCompatibilityMode.wdWord2007) 
     oDoc.Close() 
     oApp.Quit() 
     oDoc = Nothing 
     oApp = Nothing 

一切順利罰款的開發和研製的PC上運行,但是當我發佈,供離線安裝並將其部署到裝有Office 2007的Windows XP的客戶端PC上時,它會在oDoc.SaveAs2行上發生錯誤,並導致程序崩潰。我的搜索結果足夠了,但找不到解決方案。有人請幫我儘快

回答

3

From MSDN

SaveAs2
這種方法會出現在智能感知在Word 2007箇中針對.NET Framework 4的項目。然而,這個屬性不能在Word 2007箇中使用項目

順便說一句,如果你在這個網站上搜索,你發現你的問題的響應here

你可以檢查安裝在U當前的Word版本ser PC使用此代碼:

string v = _myWordApp.Version; 
switch(v) 
{ 
    case "7.0": 
    case "8.0": 
    case "9.0": 
    case "10.0": 
    _myWordDoc.SaveAs2000(ref _documentFile, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing); 
     break; 
    case "11.0": 
    case "12.0" 
    _myWordDoc.SaveAs(ref _documentFile, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, ref _nothing); 
    case "14.0" 
    _myWordDoc.SaveAs2(ref _documentFile, ref WdSaveFormat.wdFormatHTML, 
       ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, 
       ref Microsoft.Office.Interop.Word.WdCompatibilityMode.wdWord2007); 
     break; 
    default: 
     errorText = "Not able to get Word Version" 
     break; 
} 

對不起,C#代碼,但它很容易翻譯。

+1

感謝您對基於Office版本的「保存」方法的說明!我得到'RPC_E_SERVERFAULT',因爲我使用了不正確的'SaveAs'方法。 – SliverNinja 2013-01-24 20:56:32