2012-03-28 31 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