EDN Admin
Well-known member
My application crashes when trying to save a word document as text. The error at SaveAs is "Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"
I am opening and manipulating a Word 2003 Document (using Word 2007) and then trying to save it as a text file.
Very frustrating. Any help would be greatly appreciated.
Thanks
--------------------------------------------------------------------------------------------<br/>
Code that opens and manipulates a Word 2003 document up here<br/>
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------<br/>
Save the document as a text file below<br/>
--------------------------------------------------------------------------------------------<br/>
<br/>
Dim strDocName As String<br/>
Dim strDocPath As String<br/>
Dim intPos As Integer<br/>
<br/>
Find position of extension in file name<br/>
strDocName = oDoc.Name<br/>
intPos = InStrRev(strDocName, ".")<br/>
<br/>
Strip off extension and add ".txt" extension<br/>
strDocName = strDocName.Substring(0, intPos)<br/>
strDocName = strDocName & "txt"<br/>
<br/>
strDocPath = String.Concat(oDoc.Path, strDocName)<br/>
<br/>
strDocPath = "C:FolderFile.txt"<br/>
<br/>
Save file as text document with the same name as the original file.<br/>
oDoc.SaveAs(FileName:=strDocPath, FileFormat:=Text, LockComments:=False, Password:="", _<br/>
AddToRecentFiles:=False, WritePassword:="", ReadOnlyRecommended:=False, _<br/>
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _<br/>
SaveAsAOCELetter:=False, Encoding:=1252, InsertLineBreaks:=False, _<br/>
AllowSubstitutions:=False, LineEnding:=Word.WdLineEndingType.wdCRLF, _<br/>
AddBiDiMarks:=False)<br/>
<br/>
Save and close the document <br/>
oDoc.Close()<br/>
oDoc = Nothing<br/>
oWord.Quit()<br/>
oWord = Nothing
View the full article
I am opening and manipulating a Word 2003 Document (using Word 2007) and then trying to save it as a text file.
Very frustrating. Any help would be greatly appreciated.
Thanks
--------------------------------------------------------------------------------------------<br/>
Code that opens and manipulates a Word 2003 document up here<br/>
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------<br/>
Save the document as a text file below<br/>
--------------------------------------------------------------------------------------------<br/>
<br/>
Dim strDocName As String<br/>
Dim strDocPath As String<br/>
Dim intPos As Integer<br/>
<br/>
Find position of extension in file name<br/>
strDocName = oDoc.Name<br/>
intPos = InStrRev(strDocName, ".")<br/>
<br/>
Strip off extension and add ".txt" extension<br/>
strDocName = strDocName.Substring(0, intPos)<br/>
strDocName = strDocName & "txt"<br/>
<br/>
strDocPath = String.Concat(oDoc.Path, strDocName)<br/>
<br/>
strDocPath = "C:FolderFile.txt"<br/>
<br/>
Save file as text document with the same name as the original file.<br/>
oDoc.SaveAs(FileName:=strDocPath, FileFormat:=Text, LockComments:=False, Password:="", _<br/>
AddToRecentFiles:=False, WritePassword:="", ReadOnlyRecommended:=False, _<br/>
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _<br/>
SaveAsAOCELetter:=False, Encoding:=1252, InsertLineBreaks:=False, _<br/>
AllowSubstitutions:=False, LineEnding:=Word.WdLineEndingType.wdCRLF, _<br/>
AddBiDiMarks:=False)<br/>
<br/>
Save and close the document <br/>
oDoc.Close()<br/>
oDoc = Nothing<br/>
oWord.Quit()<br/>
oWord = Nothing
View the full article