2012-03-28 11 views
5

Ho sviluppato un'applicazione WinForm con VB.Net (VS2010) con Office 2010 Professional installato ed è una piattaforma Windows 7 a 64 bit. Il programma apre un documento in formato .doc e .rtf e tenta di salvarlo in formato htm. Sto usando i seguenti comandi:SaveAs2 Word 2010 non funziona con PC client con Word 2007

Dim sFilePath as String = "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 

Tutto va bene con lo sviluppo e in esecuzione sul PC di sviluppo, ma quando pubblico per offline l'installazione e la distribuzione sul PC client con Windows XP con Office 2007, dà errore sulla riga oDoc.SaveAs2 e il programma si blocca. Ho cercato su Google abbastanza ma non sono riuscito a trovare una soluzione. Qualcuno per favore mi aiuti ASAP

risposta

3

From MSDN

SaveAs2
Questo metodo appare in IntelliSense in Word 2007 progetti destinati a .NET Framework 4. Tuttavia, questa struttura non può essere utilizzato in Word 2007 progetti

A proposito, se cerchi su questo sito trovi la risposta al tuo problema here

Puoi controllare la versione del Word corrente installato sul tuo ser PC utilizzando questo codice:

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

Ci scusiamo per il codice C#, ma è facile da tradurre.

+1

Grazie per il chiarimento sul metodo 'Salva' basato sulla versione di Office! Stavo ricevendo il 'RPC_E_SERVERFAULT' perché stavo usando il metodo' SaveAs' errato. – SliverNinja