Always Sendkeys...

A

Angelo_R

I'm using a macro (below) that should print a document to file and then to
PDF. I'm using Sendkeys to type the file name but, as usal, it gives problem.
Sometimes it works, sometimes it does not.
Is it possible to use a different command?
Thanks

Angelo

PS I read a post here talking about filename in PDF but I could not
understand how to use it in my case


Dim PSFileName As String, PDFFileName As String, DistillerCall As String
Dim ReturnValue As Variant
'Define the path and filenames (can get the names from a cell, and add the
path & extension):
PSFileName = "c:\" & target.Offset(0, -1).Value & " invoice.PS"
PDFFileName = "c:\" & target.Offset(0, -1).Value & " invoice.PDF"
'If the files already exist, delete them:
If Dir(PSFileName) <> "" Then Kill (PSFileName)
If Dir(PDFFileName) <> "" Then Kill (PDFFileName)
'The Sendkeys characters are the full path and filename, followed by the
"Enter" key.

' These are buffered until the "print to file" screen appears:
SendKeys PSFileName & "{ENTER}", False

Application.ActivePrinter = GetFullNetworkPrinterName()
Worksheets("invoices").Range("a1:j29").PrintOut , PrintToFile:=True
'Add double quotes around the PS filename and PDF filename:
PSFileName = Chr(34) & PSFileName & Chr(34)
PDFFileName = Chr(34) & PDFFileName & Chr(34)
DistillerCall = "C:\Program Files\Adobe\Acrobat 6.0\Distillr\Acrodist.exe" & _
" /n /q /o" & PDFFileName & " " & PSFileName
'Call the Acrobat Distiller to distill the PS file. ReturnValue is zero
'if the application doesn't open correctly:
ReturnValue = Shell(DistillerCall, vbNormalFocus)
If ReturnValue = 0 Then MsgBox "Creation of " & PDFFileName & "failed."
 
D

Duncan

it might be skipping the filename too fast, try a sendkeys for
PSFileName then a line below for the enter, might give it more of a
chance.

There must be a way to do it without sendkeys but I dont know it.
 
A

Angelo_R

Tks a lot. I'll try it.
Anyway if someone knows a different method from Sendkeys I'll be happy to
test it! :)
 
D

Duncan

Angelo,

I've also discovered there is an optional wait command after sendkeys

expression.SendKeys(Keys, Wait)

I dont know if this will help you further............

Duncan
 

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