Print range as PDF with narrow margins on MAC

dsrt16

Board Regular
Joined
Jun 18, 2005
Messages
208
I am trying to print an area to a PDF file with narrow margins, so it all fits on one page. This executes perfectly on a PC, but not on a MAC.

I have tested out three codes on MAC and each one gives me a different problem.

Code #1 : Saved the PDF file in landscape but not narrow margins so it was on two pages. I had to search for the PDF to find it since I gave up trying to direct where the PDF should go. But it did print the PDF and call it [name of page] Overview. Tested on friend number 1s Mac.


Rich (BB code):
Sub Printrange1 ()

ActiveSheet.PageSetup.PrintArea = "$A$2:$K$25"
    
    
    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
        .LeftMargin = Application.InchesToPoints(0.25)
        .RightMargin = Application.InchesToPoints(0.25)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = xlPaperLetter
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = 100
        .PrintErrors = xlPrintErrorsDisplayed
    End With

Dim filesavename As String

   filesavename = Range("A2").Value & "_" & "Overview"


         ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=filesavename _
        , quality:=xlQualityStandard, includedocproperties:=True, ignoreprintareas _
        :=False, openafterpublish:=True
    

 End Sub

Code #2 : Went through the code, showed that it was processing the PDF pages, and gave the user the message, but I could not find the PDF file anywhere. I wanted to see if it printed to one page, and if it didn't, I would try the code I commented out below. However, I couldn't even find the PDF. I think it didn't even print or create one. Tested on friend number 2s Mac, so different Mac computer than ran code #1 .

Rich (BB code):
Sub Printrange1()

 
#If  Mac Then

  
    Dim FileName As String
    

    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
        .Orientation = xlLandscape
        .LeftMargin = Application.InchesToPoints(0.25)
        .RightMargin = Application.InchesToPoints(0.25)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .FitToPagesWide = 1
    End With
    
'if it doesn't read the pagesetup
'ActiveSheet.PageSetup.Orientation = xlLandscape
'ActiveSheet.PageSetup.PaperSize = xlLegal (may need to change this)

    FileName = Range("A2").Value & "_" & "Overview"

    Range("A2:K25").ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
    FilePathName, Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
  
    MsgBox "Since you have a Mac, you can't customize the name of the PDF or where to send it. It is called [Year] Overview. Search for it to find where your computer stored it. "

#Else 

'here I have the code for the PC which lets the user navigate to where they want to save it and call it what they want using getfilesave, which doesn't work on Mac.

Code #3 : I noticed that the code above said FileName:= FilePathName, but I never defined FilePathName, so I assumed that was the problem. So I tried this code. However, this was the worst of all because it highlighted the bold portion of the code and gave an object error. It wouldn't even execute. Also on friend number 2s Mac.

Rich (BB code):
Sub Printrange1()

 
#If  Mac Then

  
    Dim FileName As String
    

    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
        .Orientation = xlLandscape
        .LeftMargin = Application.InchesToPoints(0.25)
        .RightMargin = Application.InchesToPoints(0.25)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .FitToPagesWide = 1
    End With
    
'if it doesn't read the pagesetup
'ActiveSheet.PageSetup.Orientation = xlLandscape
'ActiveSheet.PageSetup.PaperSize = xlLegal (may need to change this)

    Dim FName As Variant
    
    FName = Range("A2").Value & "_" & "Overview"
    
    <b>Range("A2:K25").ExportAsFixedFormat Type:=xlTypePDF, FileName:=FName _
    , Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True</b>
  
    MsgBox "Since you have a Mac, you can't customize the name of the PDF or where to send it. It is called [Year] Overview(example: 2018 Overview). Search for it to find where your computer stored it. "

#Else 

'PC Code here


I just want to print a range to PDF and have it fit on one page. This works great on PC, but Macs are giving me problems right and left with this task. Any ideas?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top