Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default automated print to pdf

hi all,

i have adobe acrobat 6.0 pro and i wanted to be able to automatically
generate a .pdf file and have it e-mailed.

i have gotten the "print to pdf" working ok, and also the "e-mail file"
working. the only thing i am having trouble with is getting the pdf to print
without any user intervention (ie it always prompts for a filename).

does anyone know how to do this?

tia

J
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default automated print to pdf

here's a complete solution (hope it helps someone)

Public Const pdfPrinter As String = "Adobe PDF o"
' this constant is defined to choose the printer based on a name, the text
' name must be 11 characters long for this example. change the
' ChoosePrinter function to suit

Private Declare Function GetProfileString Lib "kernel32" Alias
"GetProfileStringA" (ByVal lpAppname As String, ByVal LpKeyName As String,
ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As
Long) As Long

sub printPDF()
Dim myPDF As PdfDistiller, PSfilename As String, PDFfilename As String
Set myPDF = New PdfDistiller

' Define the postscript filename
PSfilename = docpath & "temp.ps"
' Define the .pdf filename
PDFfilename = docpath & Sheets("Work
Order").Range("WorkOrderNumber") & ".pdf"

Sheets("Invoice").Select
ActiveSheet.PageSetup.PrintArea = "$C$2:$L$59"
With ActiveSheet.PageSetup
.LeftHeader = ""
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0)
.PrintComments = xlPrintNoComments
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
End With
ActiveSheet.PrintOut copies:=1, preview:=False,
ActivePrinter:=ChoosePrinter(pdfPrinter), PrintToFile:=True, collate:=True,
PrToFilename:=PSfilename
myPDF.FileToPDF PSfilename, PDFfilename, ""
Kill docpath & "temp.ps"
Kill docpath & "*.log"
end sub

Public Function ChoosePrinter(printerType As String) As String
Dim vaList, i
'Get all printers
vaList = PrinterFind
For i = 0 To UBound(vaList)
If Mid(vaList(i), 1, 11) = printerType Then
ChoosePrinter = vaList(i)
Exit For
End If
Next i

End Function


Public Function PrinterFind(Optional Match As String) As String()
Dim n%, lRet&, sBuf$, sCon$, aPrn$()
Const lLen& = 1024, sKey$ = "devices"


'-----------------------------Â*------------------------------Â*-------
'written by keepITcool


'requires xl2000 or newer.
'returns a zerobased array of complete localized printer strings
'results are filtered on Match string, if no result the ubound = -1
'-----------------------------Â*------------------------------Â*-------


'Split ActivePrinter string to get localized word for "on"
aPrn = Split(Excel.ActivePrinter)
sCon = " " & aPrn(UBound(aPrn) - 1) & " "


'Read all installed printers (1k bytes s/b enough)
sBuf = Space(lLen)
lRet = GetProfileString(sKey, vbNullString, vbNullString, sBuf, lLen)
If lRet = 0 Then
Err.Raise vbObjectError + 513, , "Can't read Profile"
Exit Function
End If


'Split buffer string
aPrn = Split(Left(sBuf, lRet - 1), vbNullChar)
'Filter array on Match
If Match < vbNullString Then aPrn = Filter(aPrn, Match, -1, 1)


For n = LBound(aPrn) To UBound(aPrn)
'Add 16bit portname for each Printer
sBuf = Space(lLen)
lRet = GetProfileString(sKey, aPrn(n), vbNullString, sBuf, lLen)
aPrn(n) = aPrn(n) & sCon & _
Mid(sBuf, InStr(sBuf, ",") + 1, lRet - InStr(sBuf, ","))
Next
'Return the result
PrinterFind = aPrn


End Function
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting up automated print function in VB Harmon Excel Discussion (Misc queries) 0 March 23rd 07 02:44 PM
Automated Footer SUE R Excel Discussion (Misc queries) 5 May 10th 06 08:56 PM
Can This Be Automated? [email protected] Excel Programming 4 January 19th 05 08:01 PM
Automated Print in Macro? Michael Kreft Excel Programming 0 July 15th 03 08:15 AM
Automated Print in Macro? Patrick Molloy[_3_] Excel Programming 0 July 15th 03 07:34 AM


All times are GMT +1. The time now is 04:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"