Results 1 to 5 of 5

Thread: using MS Word

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2004
    Posts
    29

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2004
    Posts
    29

    Re: using MS Word

    thanks for the help

  4. #4
    Hyperactive Member The_Duck's Avatar
    Join Date
    May 2005
    Location
    Leamington, UK
    Posts
    351

    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

  5. #5
    New Member
    Join Date
    May 2005
    Posts
    5

    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
  •  



Click Here to Expand Forum to Full Width