I have 2 sheets that i need to save as a single PDF / print to PDF upto 48 times, they make train driving simulator timetables,
I update the times for each services timetable depending on a service number selected from a dropdown list (XLookup, then it offset all the times in the timetable by however many minutes or hours are relevant, and also changes the front cover with the service number and some random date and time generators)
I wanted a way to have a button i press that would save / print as PDF the 2 relevant sheets and use the number in a cell as the name for the saved file... i have this bit working with help from someone on reddit,
But then i wanted the macro/VBA script to advance the timetable to the next one via the dropdown list, then do the save as / print PDF thing again, this time with the now different number from the cell as the filename.
And to repeat this until it gets to the end of the dropdown list (so some timetables will be 24 in total, but some are 48)
I asked about this on reddit the other day, and was given some VBA code, it selects the relevant sheets, gets the service number and uses the ExportAsFixedFormat function.
but i've found out that doing it like this using the ExportAsFixedFormat function results in a much larger PDF size, i.e. if i print the 2 sheets manually using the print dialogue in excel, the resulting files will be around 55Kb in size (i use ClawPDF printer, as i like how it can remove all the metadata when saving)
So when using the ExportAsFixedFormat 'macro' i get either a ~240 Kb file, or if i use 'Quality:=xlQualityMinimum' in the VBA, it makes them ~130 Kb in size, the idea of the project is to load a folder of timetables onto a kindle type e-ink reader, so i really need the pdf files to be as small as possible (they are just text and lines, no images)
Below is what i am using now.
It is possible to have a VBA code thing that will save the 2 pages using the 'print to pdf' method, so it uses the PDF printer which compresses them it seems, but still automate using the number in a cell as the save as file name?
I update the times for each services timetable depending on a service number selected from a dropdown list (XLookup, then it offset all the times in the timetable by however many minutes or hours are relevant, and also changes the front cover with the service number and some random date and time generators)
I wanted a way to have a button i press that would save / print as PDF the 2 relevant sheets and use the number in a cell as the name for the saved file... i have this bit working with help from someone on reddit,
But then i wanted the macro/VBA script to advance the timetable to the next one via the dropdown list, then do the save as / print PDF thing again, this time with the now different number from the cell as the filename.
And to repeat this until it gets to the end of the dropdown list (so some timetables will be 24 in total, but some are 48)
I asked about this on reddit the other day, and was given some VBA code, it selects the relevant sheets, gets the service number and uses the ExportAsFixedFormat function.
but i've found out that doing it like this using the ExportAsFixedFormat function results in a much larger PDF size, i.e. if i print the 2 sheets manually using the print dialogue in excel, the resulting files will be around 55Kb in size (i use ClawPDF printer, as i like how it can remove all the metadata when saving)
So when using the ExportAsFixedFormat 'macro' i get either a ~240 Kb file, or if i use 'Quality:=xlQualityMinimum' in the VBA, it makes them ~130 Kb in size, the idea of the project is to load a folder of timetables onto a kindle type e-ink reader, so i really need the pdf files to be as small as possible (they are just text and lines, no images)
Below is what i am using now.
It is possible to have a VBA code thing that will save the 2 pages using the 'print to pdf' method, so it uses the PDF printer which compresses them it seems, but still automate using the number in a cell as the save as file name?
VBA Code:
Sub Save_As_PDF_Using_Service_Number()
Dim fPath As String
Dim fName As String
Dim wsStart As Worksheet
'What folder to save in?
fPath = "C:\Users\abcd\Documents\FolderName\411XX Timetables (VBA)\"
'Note where we start at
Set wsStart = ActiveSheet
'Error check
If Right(fPath, 1) <> Application.PathSeparator Then
fPath = fPath & Application.PathSeparator
End If
'Where is the name for PDF?
fName = ThisWorkbook.Worksheets("TimeTable_141XX").Range("T5").Value
'Make the PDF
Application.ScreenUpdating = False
ThisWorkbook.Sheets(Array("Front_Cover", "TimeTable_141XX")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPath & fName, Quality:=xlQualityMinimum
wsStart.Select
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: