Office Interop Exception in VB.NET1.1, Please help
-
Hi, I am using VB.NET1.1 and office 2003. I have created a object of Word document, opening it, writing some data into the document Printing it and finally closing the document. However it is throwing this exception while closing the document. exception from hresult 0x800A140C Here is the code piece: If (IsNothing(appWord) = True) Then appWord = ModWord.GetWordApplication End If docProposal = ModWord.GetDocument(appWord, lstrFileName) lstrFileName = docProposal.FullName lstrFile = docProposal.Name If (docProposal.MailMerge.Fields.Count > 0) Then For Each bk As Word.MailMergeField In docProposal.MailMerge.Fields bk.Locked = True Next ' Create a data source containing the field data. docProposal.MailMerge.CreateDataSource(Name:=lstrDataFile, HeaderRecord:="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37") ' Open the file to insert data. 'docProposalData = appWord.Documents.Add(lstrDataFile, Visible:=False) docProposalData = appWord.Documents.Open(lstrDataFile, Visible:=False) With docProposalData.Tables.Item(1) lint = 1 For Each lstr In laHdg .Cell(1, lint).Range.Text = lstr lint += 1 Next lint = 1 For Each lstr In laData .Cell(2, lint).Range.Text = lstr lint += 1 Next End With ' Save and close the data file. docProposalData.SaveAs(lstrDataFile) Application.DoEvents() 'The code is breaking at this line. docProposalData.Close(Word.WdSaveOptions.wdDoNotSaveChanges, , False) Application.DoEvents() Please help For Reference here is GetDocument function Public Shared Function GetDocument(ByVal wordApplication As Word.Application, ByVal filename As String) As Word.Document If wordApplication Is Nothing Then Throw New ApplicationException("Word application is nothing.") End If Dim docProposal As Word.Document = wordApplication.Documents.Open(filename) If filename.EndsWith(".dot") Then For Each templ