#1
|
|||
|
|||
Correct syntax for printing from VBA
Could somebody (Graham?) please tell me where I am going wrong with the syntax in this snippet:
Code:
curPtr$ = Application.ActivePrinter Application.ActivePrinter = "Microsoft Print to PDF" ActiveDocument.PrintOut False, False, 0, txtFilename, 0, 0, 0, 1, 0, 0, True Application.ActivePrinter = curPtr$ Phil |
#2
|
||||
|
||||
Microsoft doesn't permit the inclusion of a filename when printing to PDF.
You need instead Code:
ub SaveAsPDF() Dim strDocName As String Dim strPath As String Dim intPos As Integer Start: 'Find position of extension in filename strDocName = ActiveDocument.Name strPath = ActiveDocument.path & "\" intPos = InStrRev(strDocName, ".") If intPos = 0 Then ActiveDocument.Save GoTo Start End If strDocName = Left(strDocName, intPos - 1) strDocName = strPath & strDocName & ".pdf" ActiveDocument.ExportAsFixedFormat OutputFileName:=strDocName, _ ExportFormat:=wdExportFormatPDF, _ OpenAfterExport:=False, _ OptimizeFor:=wdExportOptimizeForPrint, _ Range:=wdExportAllDocument, From:=1, to:=1, _ Item:=wdExportDocumentContent, _ IncludeDocProps:=True, _ KeepIRM:=True, _ CreateBookmarks:=wdExportCreateHeadingBookmarks, _ DocStructureTags:=True, _ BitmapMissingFonts:=True, _ UseISO19005_1:=False lbl_Exit: Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Oh, what a pain! Thank you Microsoft!
And thanks, Graham, for your explanation. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Correct syntax for PtrSafe Function AccessibleObjectFromWindow | Paul Cain | Excel Programming | 2 | 11-19-2018 04:29 AM |
How do I ensure correct duplex printing? | JCF | Word | 3 | 07-14-2017 06:55 AM |
VLookup Syntax | ketbdnetbp | Excel | 2 | 04-12-2014 03:18 PM |
Can't seem to get the correct syntax for Wine list mailmerge | daym | Mail Merge | 3 | 05-02-2011 03:26 AM |
Syntax help needed | blazzercat | Excel | 3 | 07-09-2009 02:15 PM |