Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-22-2021, 10:29 PM
gmayor's Avatar
gmayor gmayor is offline Correct syntax for printing from VBA Windows 10 Correct syntax for printing from VBA Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default


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
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Correct syntax for printing from VBA 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
Correct syntax for printing from VBA VLookup Syntax ketbdnetbp Excel 2 04-12-2014 03:18 PM
Correct syntax for printing from VBA Can't seem to get the correct syntax for Wine list mailmerge daym Mail Merge 3 05-02-2011 03:26 AM
Correct syntax for printing from VBA Syntax help needed blazzercat Excel 3 07-09-2009 02:15 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:30 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft