+ Reply to Thread
Results 1 to 4 of 4

VBA Print to PDF

  1. #1
    Registered User
    Join Date
    10-01-2019
    Location
    Australia
    MS-Off Ver
    1908
    Posts
    9

    Exclamation VBA Print to PDF

    Hi guys,

    I have the VBA code below to print the active worksheet to PDF in the Downloads folder. It prints to A4 sheet size on my computer BUT on my colleagues computer it prints it to Letter paper size. We want it to always print to A4 paper size, regardless of what computer it's used on or Excel version is being run.

    Thanks in advance guys

    See below:



    Sub Print_to_PDF()
    '
    ' PDF_Single_Page Macro
    ' Saves to PDF Ctrl+Shft+End page selection area
    '
    RFIPrefix = "RFI "
    RFINum = Range("E4") & " - "
    JobNum = Range("B4") & " - "
    JobName = Range("B5")
    Exten = ".pdf"
    '
    Range("A1:E28").Select
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    ChDir "C:\Users" & Environ("Username") & "\Downloads"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:\Users" & Environ("Username") & "\Downloads" & RFIPrefix & RFINum & JobNum & JobName & Exten _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=True, OpenAfterPublish:=False
    With ActiveSheet.PageSetup
    .LeftHeader = ""
    .CenterHeader = ""
    .RightHeader = ""
    .LeftFooter = ""
    .CenterFooter = ""
    .RightFooter = ""
    .LeftMargin = Application.InchesToPoints(0)
    .RightMargin = Application.InchesToPoints(0)
    .TopMargin = Application.InchesToPoints(0)
    .BottomMargin = Application.InchesToPoints(0)
    .HeaderMargin = Application.InchesToPoints(0)
    .FooterMargin = Application.InchesToPoints(0)
    .CenterHorizontally = True
    .CenterVertically = False
    .PaperSize = xlPaperA4
    .BlackAndWhite = False
    .FitToPagesWide = 1
    .FitToPagesTall = False
    End With
    Application.PrintCommunication = True

    End Sub

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA Print to PDF


    Hi,

    as you must achieve the print page setup before to export to pdf and not after …

  3. #3
    Registered User
    Join Date
    10-01-2019
    Location
    Australia
    MS-Off Ver
    1908
    Posts
    9
    Quote Originally Posted by Marc L View Post

    Hi,

    as you must achieve the print page setup before to export to pdf and not after …
    Hi Marc,

    Ok I've tried putting the page setup section at the top to run first but still no luck, are you able to show me what you mean?

    Thank you

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA Print to PDF


    After Print.Communication=True …
    After running the VBA procedure check manually the page setup if it is well setup as expected.
    And it seems a back slash (Path Separator) is missing in your path …
    Last edited by Marc L; 05-09-2023 at 08:18 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. ignore margin print area warning when printing from normal print menu
    By nigelog in forum Word Formatting & General
    Replies: 1
    Last Post: 09-21-2018, 05:48 PM
  2. Print until a specified point, print a pdf then print from excel again
    By orkula in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-18-2017, 10:17 AM
  3. Disabled print toolbar and menu but Print Macro button cannot print also...
    By zein97 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2014, 01:42 PM
  4. Set print area of selected range then print preview if ok then print the document!
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2014, 07:10 AM
  5. VBA to set print range, open box asking for print qty, print, then redefine print area
    By galvinpaddy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2012, 06:43 PM
  6. Replies: 4
    Last Post: 02-17-2006, 08:36 AM
  7. [SOLVED] Pivot Table macro to set print area and print details of drill down data
    By Steve Haskins in forum Excel General
    Replies: 2
    Last Post: 12-28-2005, 01:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1