Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-04-02
2
Medium Priority
?
4,659 Views
Last Modified: 2008-01-09
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?
0
Comment
Question by:Arrummzen
2 Comments
 
LVL 17

Accepted Solution

by:
wobbled earned 500 total points
ID: 16358454
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
 
LVL 1

Author Comment

by:Arrummzen
ID: 16366738
Works perfect....  Thanks!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month10 days, left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question