-
using MS Word
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:
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
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.
Help please!
Thank you
-
Re: using MS Word
I've done similar things with Excel and you can set the Saved property of an Excel workbook to True, which fools Excel into thinking it has been saved even if it hasn't and thus Excel does not prompt to save. I would guess that a Word.Document object has an equivalent property.
-
Re: using MS Word
-
Re: using MS Word
There is a property in Excel (which i guess exists in Word)
DisplayAlerts which you can use to turn off user interaction.
I would also recommend setting IgnoreRemoteRequests to True !!
http://www.vbforums.com/showthread.p...cel+Automation
-
Re: using MS Word
You could try something like this so there is no alerts for the user
'Set Word to display not alerts
InternalWordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone