Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Setting up automated print function in VB | Excel Discussion (Misc queries) | |||
Automated Footer | Excel Discussion (Misc queries) | |||
Can This Be Automated? | Excel Programming | |||
Automated Print in Macro? | Excel Programming | |||
Automated Print in Macro? | Excel Programming |