What is happening?
At the end of the PDFCreator routines on this site, we release PDFCreator with (a variation of) the following line:
Set pdfjob = Nothing
Killing the running process:
The very first thing that we need to do to enable our code to run again is to close the running instance of PDFCreator. The steps to do this are listed below, but you should take great care to follow them exactly. Killing the wrong process could cause damage to your system, so make sure that you have the correct process selected! (You may want to print this, as the Task Manager will sit on top of all of your open windows.)
- Right click your taskbar
- Select Task Manager
- Click on the Processes tab
- Click Image Name until your list is sorted in alphabetical order
- Scroll down the list until you find PDFCreator.exe
- Right click PDFCreator.exe and choose End Process
- Once the process disappears, close the Task Manager
On March 1st, 2007, I updated all the PDFCreator articles on the site to change the way PDFCreator was released. Check your code to see if you have a loop near the end that looks something like this:
'Wait until the PDFCreator queue is clear Do Until pdfjob.cCountOfPrintjobs = 0 DoEvents Loop
'Wait until the PDF file shows up then release the objects Do Until Dir(sPDFPath & sPDFName) <> "" DoEvents Loop
This article was originally published with the steps listed below to pause the PDFCreator code as I didn't have a better method at the time. Rather than remove them outright, I decided to leave them as an alternate way to work around the problem of closing PDFCreator. The method that follows is anything but elegant, but it is effective.
Alternative One - No time to adjust the code:
If you don't have time sleuth your your code, you could try closing all extra running programs to give your RAM and processor as much resources as possible. Often that is enough to allow a PDFCreator loop to complete.
The problems with this, obviously, are:
- We shouldn't need to close down our other applications to do this
- It won't always work
- It's not reliable when deploying code to clients. (Their systems will have different resource loads.)
We can deal with this issue by intentionally slowing down our code with a pause. Personally, this goes against my grain, and is the reason I kept pursuing a better way. I want my code to complete as fast as possible, but if you don't mind this method, it will work.
The actual length of the pause that is required will depend on your system, your RAM, your processor, and how many applications you have open when the PDFCreator code is running. It may take some experimentation to get it correct, and you should be warned that it may not work on your client's PC. You may need to increase the pause there to be safe.
The following line of code just will add a 3 second pause in the routine. To adjust this pause, just increase or decrease the 3 to as much or little as you need.
Application.Wait Now + TimeValue("0:0:3")
'Wait until the PDF file shows up then release the objects Do Until Dir(sPDFPath & sPDFName) <> "" DoEvents Loop 'Wait a bit longer for PDF Creator to finish Application.Wait Now + TimeValue("0:0:3") pdfjob.cClose Set pdfjob = Nothing