VBA macro to print and close word document will not pause between actions resulting in failure to close application

I have a VBA macro triggered from C# following a mail merge in Word 2000 that should automatically print and close the document:

Sub PrintEnvelope()
'
' Print_Envelope Macro
' Macro created 4/1/2006'
    Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
        wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
        Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _
        PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
'Pause Task
    Dim PauseTime, Start
    PauseTime = 10    ' Set duration.
    Start = Timer    ' Set start time.
    Do While Timer < Start + PauseTime
        DoEvents    ' Yield to other processes.
    Loop
'Close Document
   Application.Documents.Close False, False, False
    Dim wordApp As Object
    Set wordApp = GetObject(, "Word.Application")
    wordApp.Quit
    Set wordApp = Nothing
End Sub

The problem I am up against is that each of these 3 macro sets works fine when launched manually one at a time.  But if I try to run them together, the print will wait until after the pause, and the close error will still occur.  I need the print to occur, then a brief pause of 10 seconds, then close the document.  Is there a way to force the print command in the first portion of the macro, then pause for 10 seconds, then perform the last part of the code?
LVL 1
ArrummzenAsked:
Who is Participating?
 
wobbledCommented:
There is a function called onTime where you can set it to call a macro after a specified amount of time has passed eg

Application.OnTime When:=Now + TimeValue("00:00:15"), _
    Name:="Project1.Module1.Macro1"

This should work for tyour project.  One thing to note is that you can only have ONE onTime call working at once.

Regards

W
0
 
ArrummzenAuthor Commented:
Works perfect....  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.