I have developed a WinForm Application with VB.Net (VS2010) having Office 2010 Professional Installed, and it is 64-bit Windows 7 Platform. The program opens a .doc and .rtf format document, and attempts to save it in htm format. I am using following commands:
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
All goes fine with development and running on development PC, but when I publish it for offline installation, and deploy it on Client PC having Windows XP with Office 2007, it gives error on oDoc.SaveAs2 line, and program crashes. I have googled enough but could not find a solution to it. Somebody please help me ASAP
From MSDN
SaveAs2
This method appears in IntelliSense in Word 2007 projects that target the .NET Framework 4. However, this property cannot be used in Word 2007 projects
By the way, if you search on this site you find the response at your problem here
You could check the version of the current Word installed on the user PC using this code:
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;
}
Sorry for the C# code, but it's easy to translate.