VBA to print to pdf is sending to printer (Mac OS)

ALO_FLX

New Member
Joined
Dec 28, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi,

Apologies if this is answered elsewhere but I've searched high and low for the answer to this one and even thought I'd found it when I found a Ron De Bruin post on it so tweaked my code to align with his and still no luck.

Essentially I have a workbook that runs a list through a template and prints each employee's payslip. However, I moved to Mac and it no longer worked hence my search.

Below is the code and any help would be massively appreciated.

Thanks in advance.

VBA Code:
Sub Print_All_To_PDF()

' Print_to_PDF Macro

Dim strValidationRange As String
Dim rngValidation As Range
Dim rngDepartment As Range
    
Dim FileName As String
Dim FolderName As String
Dim Folderstring As String
Dim FilePathName As String

' Turn off screen updating
Application.ScreenUpdating = False

' Identify the source list of the data validation
strValidationRange = Worksheets("Payslip Template").Range("A11").Validation.Formula1
Set rngValidation = Range(strValidationRange)

' Set the value in the selection cell to each selection in turn
' and print the results.
For Each rngDepartment In rngValidation.Cells
Worksheets("Payslip Template").Range("A11").Value = rngDepartment.Value
    'Name of the folder in the Office folder
    FolderName = "Payslips"
    'Name of the pdf file
    FileName = "Payslip - " & Worksheets("Sheet Data").Range("B5") & ". " & Worksheets("Payslip Template").Range("A9").Value _
    & " - " & Worksheets("Payslip Template").Range("A11").Value & ".pdf" _

    FilePathName = FolderName & Application.PathSeparator & FileName

    'expression A variable that represents a Workbook, Sheet, Chart, or Range object.
    'the parameters are not working like in Excel for Windows
    Worksheets("Payslip Template").ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
    FilePathName, Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False
Next
' Turn screen updating back on
Application.ScreenUpdating = True

MsgBox "Payslip run complete", vbOKOnly, "Payroll"

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
So from your title, you are saying that the ExportToFixedFormat line is actually printing the file on your printer?
 
Upvote 0
Correct, took me a while to suss the issue as the printer was offline.
 
Upvote 0
Which version/build of Office are you running?
 
Upvote 0
I know you have 365 as it's in your profile, but which actual version number and build is it? Different features (and bugs) are present in different builds.
 
Upvote 0
I know you have 365 as it's in your profile, but which actual version number and build is it? Different features (and bugs) are present in different builds.
Apologies, I wasn't 100% on what you were after.

In terms of Version Number it is 16.68.

Build wise, I'm on Ventura 13.0.1

Hopefully this was the info you were after but please let me know if there is anything else. Appreciate any help you can offer.

Cheers
 
Upvote 0
I am having the exact same problem. This line is not generating a PDF but instead sending it directly to the printer and it's making me feel like I'm taking crazy pills. It was working fine a week ago, with no notable changes to my work environment.

VBA Code:
ThisWorkbook.Sheets("Order").ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "/" & savename & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False
 

Attachments

  • Screenshot 2024-01-19 at 11.49.46.png
    Screenshot 2024-01-19 at 11.49.46.png
    72 KB · Views: 27
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,195
Members
452,616
Latest member
intern444

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