SendKeys hangs the system for about a minute on first execution

M

Mike Starr

I'm executing the following code and it appears that the SendKeys statement
is causing the system to "hang" for about a minute the first time it's
executed. The cursor freezes and it appears that the system is completely
hung but after a minute, the application.printout statement executes as if
nothing had happened. Anyone got any idea why it's hanging and what I can do
about it??

Thanks

Mike

pdffilename = "C:\MarketingSheets\" _
& DocumentSettings.FileName _
& LogoName _
& ".pdf" '
SendKeys pdffilename + "{enter}"
Application.PrintOut _
Range:=wdPrintAllDocument, _
Item:=wdPrintDocumentContent, _
Copies:=1, _
Pages:="", _
PageType:=wdPrintAllPages, _
Collate:=True, _
Background:=False, _
PrintToFile:=False, _
PrintZoomColumn:=0, _
PrintZoomRow:=0, _
PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0


--
 
J

Jezebel

It's not the SendKeys itself that does this, but that on the first call
you're firing up Acrobat which then loads all those pestilential and
pointless Acrobat add-ins. Acrobat is smart enough to keep itself loaded in
this context, so subsequent calls don't get this delay.

This has improved a lot with Acrobat version 7.

There are several other ways to handle the Acrobat filename problem
(Sendkeys is always a last resort!).

1. You can set Acrobat to print without prompting for filename. In this case
the output file has the same name as the document you're printing, extension
..pdf. Depending on the Acrobat version, the target folder is determined by
the 'port' on which Acrobat is installed, or defaults to MyDocuments or
User\Desktop, or is settable through Printer > Properties. So the trick in
code is simplyh to print the document, then sleep for a second or so, then
use the Name function to move it from the default name and location to
wherever you want it.

2. With Acrobat 6 you can call the PDFMaker.ConvertToPDF function. That uses
a registry setting to determine how the file is saved -- you can set this
yourself. The settings are somewhere under HKCU\Software\Acrobat\...

3. You can use Acrobat Distiller. Can't remember the method, but you can
pass it the filename as an argument.
 
M

Mike Starr

Jezebel

Thanks for your quick reply. The problem is that I've created a template
that I'm going to be sending to users. They will in turn use this template
to create a document. When they've finished creating the document, I've put
a toolbar button in place that they can click to create four different pdf
documents based on their document. The macro assigned to the button is what
executes the code I enclosed below. It executes that code a total of four
times. However, I don't know what the user's settings for the Acrobat
Distiller printer are nor do I have acess to the users to configure it for
them. In narrative form, here's what happens in the macro:

1. Save the document

2. Print the document to the Acrobat Distiller printer using the filename
specified (this is where the SendKeys statement gets executed).

3. Change the logo in the document footer to the logo for a different
business unit

4. Print the document to the Acrobat Distiller printer using the filename
specified (this is where the SendKeys statement gets executed).

5. Change the logo in the document footer to the logo for a different
business unit

6. Print the document to the Acrobat Distiller printer using the filename
specified (this is where the SendKeys statement gets executed).

7. Change the logo in the document footer to the logo for a different
business unit

8. Print the document to the Acrobat Distiller printer using the filename
specified (this is where the SendKeys statement gets executed).

9. Close the document without saving any of the changes made since the
beginning of macro execution.

I need the SendKeys in order to specify the path and filename because I'm
not changing the Word document filename (I originally used a SaveAs routine
to save the file under a different filename for each iteration above but
couldn't come up with a reliable method for deleting the un-needed Word
documents.). The client's objective is to end up with one Word document (the
original document file) and four different PDFs. Before I implemented the
SendKeys functionality, I had to rely on the user to browse to the
appropriate directory. That was unacceptable but there WAS NOT any delay or
hang in that process. Adding the SendKeys to this is what seems to have
caused the hang.

Again, thanks for your willingness to help. It's much appreciated.

Best regards

Mike Starr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top