|
-
May 23rd, 2005, 01:25 PM
#1
Thread Starter
Junior Member
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
Last edited by saphiroth; May 23rd, 2005 at 01:30 PM.
-
May 24th, 2005, 12:21 AM
#2
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.
-
May 24th, 2005, 07:21 AM
#3
Thread Starter
Junior Member
-
May 24th, 2005, 07:27 AM
#4
Hyperactive Member
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
-
May 24th, 2005, 10:12 AM
#5
New Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|