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.
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