Hi,
Im using the Word Reference to work with MS Word within my vb project. What I am doing is performing a mail merge with a word document and a text file. The data from the text file is writen into the word document. After the merge has occurde I want to print the document and close the word document at the same time. The code I use to do this is:
My problem is that I need to have the word document not save and print autimatically without bothering the user about anything. The things in the code kindof work but i print autimatiaclly but it still asks me to save OR it asks me if I want to print but does not ask me to save.Code:Dim cancel As Boolean = False Dim InternalWordApp As New Word.ApplicationClass Dim InternalWordDoc As New Word.Document Dim InternalWordDocTemp As New Word.Document InternalWordApp.Visible = False InternalWordDoc = InternalWordApp.Documents.Add("C:\Documents and Settings\60shipping\Desktop\GaugeProject\bin\label.doc") Try With InternalWordDoc.MailMerge cancel = False .SuppressBlankLines = True InternalWordDoc.Saved = True '.Destination = Word.WdMailMergeDestination.wdSendToPrinter .Execute(True) .Destination = Word.WdMailMergeDestination.wdSendToPrinter .Application.PrintOut() System.Threading.Thread.Sleep(2000) End With Catch ex As Exception cancel = True InternalWordDoc.Saved = True InternalWordDoc.Close() InternalWordDoc = Nothing InternalWordApp.Quit() InternalWordApp = Nothing End Try If (cancel = False) Then InternalWordDoc.Saved = True InternalWordDoc.Close() InternalWordDoc = Nothing InternalWordApp.Quit() InternalWordApp = Nothing End If End Function
Help please!
Thank you




Reply With Quote