Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Job Complete

Status
Not open for further replies.

bryhall2

Programmer
Jul 5, 2006
5
US
Hello,

I have searched extensively and have been unable to find an answer.

I currently have a macro in Word that changes some text in a text file, sends the current document to the printer, and sets the text file back to the original state(I am changing an .ini file). The problem is that I do not wish to set the INI file back to the original text until the print job is complete.

Anyone have any ideas how I would do this? I was thinking just making a loop that checks to see if print job is complete. If print job is complete then set INI file otherwise recheck print job status.

Keep in mind I do not want to check printer status, for I am printing to PDF. I am interested only in print job being complete.

Thanks for the help!
 
Set the Background argument of the PrintOut method to False

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV, thank you for the help. I had originally thought this would solve my problem. However, it does not. I believe that the final section of my code is being executed too quickly. The ini is changed before the user has the ability to save the pdf to a directory (I believe the print job is ending before the pdf is saved). I suspect that it would be impossible to determine when the pdf is actually saved to continue code execution. Perhaps my only option is to pause code execution for a set amount of time?

Any other help would be much appreciated. I have included my code below.

Thanks again.


Code:
Sub Test()


'Checks for installed pdf995
If Len(Dir("C:\Program Files\pdf995\res\pdf995.ini")) = 0 Then
MsgBox "PDF 995 Not Installed", vbOKOnly
Else
    'Turns Email On
    ChangeFileOpenDirectory "C:\Program Files\pdf995\res\"
    Documents.Open FileName:="pdf995.ini", ConfirmConversions:=False, ReadOnly:= _
        False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
        "", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
        Format:=wdOpenFormatAuto, Encoding:=1252
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "Email=0"
        .Replacement.Text = "Email=1"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ActiveDocument.Save
    ActiveDocument.Close
    

   
   ' Declares Variables
   Dim strPrinterName As String
   Dim strPrintOrder As String
   
   ' Assign variable
   strPrinterName = Application.ActivePrinter
   ActivePrinter = "PDF995"
    
    'Prints
    With Options
    strPrintOrder = .PrintReverse
    .PrintReverse = False
    End With
    Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
     wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
     ManualDuplexPrint:=False, Collate:=True, PrintToFile:= _
     False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
     PrintZoomPaperHeight:=0, Background:=False
    
    'Sets Printer to original default
    
    With Options
    .PrintReverse = strPrintOrder
    End With
    ActivePrinter = strPrinterName

   'Turns Email off
   ChangeFileOpenDirectory "C:\Program Files\pdf995\res\"
   Documents.Open FileName:="pdf995.ini", ConfirmConversions:=False, ReadOnly:= _
        False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
        "", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
        Format:=wdOpenFormatAuto, Encoding:=1252
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "Email=1"
        .Replacement.Text = "Email=0"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
       .MatchWholeWord = True
       .MatchWildcards = False
       .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ActiveDocument.Save
    ActiveDocument.Close

End If
End Sub
 
A couple of thoughts.

Check for presence of .pdf in a loop before continuing.

If it is likely to exist already, be sure to delete it before starting or use a loop which checks the time stamp (modified) of the the .pdf before continuing.

HTH

 
Help me out here, as I am trying understand.

1. Why are you doing a ChangeFileOpenDirectory? Why not just do a file open?
Code:
Documents.Open FileName:="C:\Program Files\pdf995\res\pdf995.ini"
Is there some particular reason for changing the open directory? You certainly do not need to. And you DEFINITELY do not need to do it twice. You run
Code:
ChangeFileOpenDirectory "C:\Program Files\pdf995\res\"[/code a second time - even though there is no change in between.

2.  You open pdf995.ini, make a change...then save and close it.  You print from the active document, then RE-open pdf995.ini, and change the text back again.

I don't get it.  WHY are you doing this?????  Why are you saving and closing pdf995.ini, then re-opening it?  Seems strange.  Why not just keep it open, and switch to the other document?

3.  I am not even getting why you are doing anything with saving/closing/re-opening/saving/closing pdf995.ini at all.  Especially as the end result is NO change to the file.  What is thepurpose for this?  You can check for "Email=0", [b]or[/b] "Email=1" if that value is what is the point.

Gerry
[url=http://www3.telus.net/public/fumei/]My paintings and sculpture[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top