Print without print dialog

Hi

I want to print a document in Microsoft Word 2000 with the following code:

Sub Test ()
    Documents.Open FileName:="C:\doc\letter.doc"
    Set myMerge = ActiveDocument.MailMerge
    myMerge.OpenDataSource ("C:\doc\address.txt")
    If myMerge.State =  wdMainAndSourceAndHeader Or _
       myMerge.State = wdMainAndDataSource Then
        With myMerge.DataSource
            .FirstRecord = 1
            .LastRecord = 1
        End With
    End If
    With myMerge
        .Destination = wdSendToPrinter
        .Execute
    End With
End Sub

Execute prints the document, but always, the print dialog will be show.

Is is possible, to print without this dialog? How can I do that?

Thanks

Hans
hstoesselAsked:
Who is Participating?
 
MaximkaConnect With a Mentor Commented:
Try this simpliest method.
Just put in into form with command button with Command1 name and run it.


Option Explicit
Private Declare Function ShellExecuteAny Lib "shell32.dll" Alias "ShellExecuteA" ( _
                         ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
                         ByVal lpParameters As Any, ByVal lpDirectory As Any, ByVal nShowCmd As Long) _
                         As Long

Private Const SW_SHOWMINNOACTIVE = 7

Private Sub Command1_Click()

    Dim lRet As Long
    Dim l As Long
   
    'executing the ShellExecute print Windows method
    lRet = ShellExecuteAny(l, "print", "C:\doc\address.txt", ByVal 0&, ByVal 0&, SW_SHOWMINNOACTIVE)

End Sub

Hope this will help You.
Cheers.



0
All Courses

From novice to tech pro — start learning today.