Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-04-2024, 01:43 PM
Jakov93 Jakov93 is offline Adjust Page Size Using PrintOut Method for File Print to PDF by VBA Windows 10 Adjust Page Size Using PrintOut Method for File Print to PDF by VBA Office 2010
Advanced Beginner
Adjust Page Size Using PrintOut Method for File Print to PDF by VBA
 
Join Date: Jul 2021
Posts: 51
Jakov93 is on a distinguished road
Default Adjust Page Size Using PrintOut Method for File Print to PDF by VBA

Hi,
I use this code to print the document by "Application.PrintOut" method to PDF file, I don't want it by "ExportAsFixedFormat" because I have an issue with this method (italic text loses formatting).
Code:
Sub SaveAsPDF()
    Dim sPrinter As String
    Dim strDocName As String
    Dim strPath As String
    Dim intPos As Integer
    'Find position of extension in filename
    strDocName = ActiveDocument.Name
    strPath = ActiveDocument.Path & "\"
    intPos = InStrRev(strDocName, ".")
    strDocName = Left(strDocName, intPos - 1)
    strDocName = strPath & strDocName & ".pdf"
    On Error GoTo lbl_Exit
    sPrinter = Application.ActivePrinter
    ActivePrinter = "Microsoft Print to PDF"
    Application.DisplayAlerts = False
    ActiveDocument.PrintOut _
        OutputFileName:=strDocName, _
        PrintToFile:=True
lbl_Exit:
    Application.DisplayAlerts = True
    Application.ActivePrinter = sPrinter
    Exit Sub
End Sub
The code works perfectly, but the only problem is the size of the output file is not as my document size
I always use A4 (210*297 mm), when I use ExportAsFixedFormat method, the output file is the same size as my document size,
but when I use "Application.PrintOut" method, the output file size is 215*279 mm, which is different from A4 size and causes some problems when printing on paper.
I changed the default paper size in "Microsoft Print to PDF" printer, but the problem persists, (see attached files).
Test_PrintOut_Method.pdf


Test_ExportAsFixedFormat_Method.pdf
So how to fix this issue?
Thanks
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with page number printout on booklet file in word2007 kenbrash Word 5 09-12-2023 03:59 PM
worksheet row to print on two or more printout lines rh62 Excel 1 06-18-2017 12:55 PM
The best practice to print 20,000 rows of 6-columns each in pdf landscape A3 page size while to repe Majdoleen Excel 0 04-25-2017 01:02 PM
Adjust Page Size Using PrintOut Method for File Print to PDF by VBA Want to print a file on a page size of 4.25"x5.5" noname Word 1 11-23-2014 10:55 PM
Adjust Page Size Using PrintOut Method for File Print to PDF by VBA vba word 2003: printout prints only the first page of the file kar64 Word VBA 2 02-15-2013 02:42 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:40 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