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."
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."