palaeontology
Active Member
- Joined
- May 12, 2017
- Messages
- 444
- Office Version
- 2016
- Platform
- Windows
I currently use the following code to print all worksheets named with a 5-digit name (eg: 34716)
I no longer want to print these sheets to paper. I would like to now save each worksheet that is named with a 5-digit code as a PDF to a location such as ...
G:\Maths Dept\STUDENT RESULTS\2019\PDF Profile Copies\CJAMI\12MathA\CHAPMAN, Ellee
however, the last 3 components of that address are fluid, and folders with those names may or may not already exist when the code is run.
In other words, there is definitely a folder at ... G:\Maths Dept\STUDENT RESULTS\2019\PDF Profile Copies .... waiting to receive PDFs, but the "CJAMI\12MathA\CHAPMAN, Ellee" section of the address is dependent on the contents of cells S5, E2 and S3 (in that order) on each of the worksheets that are to be printed (the ones that are named with a 5-digit code).
If, for example, the "CJAMI" folder doesn't already exist inside the location "G:\Maths Dept\STUDENT RESULTS\2019\PDF Profile Copies" then it would need to be created.
and if the "12MathA" folder doesn't already exist inside the "CJAMI" folder, then it would need to be created
etc.
I know that to save as a PDF, the code would have to begin with something like ...
however I really am struggling to figure how to set it up to save in a location with those three fluid components at the end (the ones that are reliant on whatever is in cells S5, E2 and S3 of the sheet being saved in PDF format.
Is this at all possible ?
Code:
For Each ws In ThisWorkbook.Worksheets If ws.Name Like "#####" Then
ws.Range("P22:U22").Font.Color = vbWhite
ws.Range("P22:U22").Interior.Color = vbWhite
ws.PageSetup.Orientation = xlLandscape
ws.PrintOut From:=1, To:=1
End If
Next ws
I no longer want to print these sheets to paper. I would like to now save each worksheet that is named with a 5-digit code as a PDF to a location such as ...
G:\Maths Dept\STUDENT RESULTS\2019\PDF Profile Copies\CJAMI\12MathA\CHAPMAN, Ellee
however, the last 3 components of that address are fluid, and folders with those names may or may not already exist when the code is run.
In other words, there is definitely a folder at ... G:\Maths Dept\STUDENT RESULTS\2019\PDF Profile Copies .... waiting to receive PDFs, but the "CJAMI\12MathA\CHAPMAN, Ellee" section of the address is dependent on the contents of cells S5, E2 and S3 (in that order) on each of the worksheets that are to be printed (the ones that are named with a 5-digit code).
If, for example, the "CJAMI" folder doesn't already exist inside the location "G:\Maths Dept\STUDENT RESULTS\2019\PDF Profile Copies" then it would need to be created.
and if the "12MathA" folder doesn't already exist inside the "CJAMI" folder, then it would need to be created
etc.
I know that to save as a PDF, the code would have to begin with something like ...
Code:
Sheets("Sheet1").Range("A1:H20").ExportAsFixedFormat Type:=xlTypePDF, _ Filename:="C:\Users\marks\Documents\Saved PDF.pdf"
however I really am struggling to figure how to set it up to save in a location with those three fluid components at the end (the ones that are reliant on whatever is in cells S5, E2 and S3 of the sheet being saved in PDF format.
Is this at all possible ?