Save sheet as pdf to a subfolder that matches the value of Cell

dandy

New Member
Joined
Apr 3, 2017
Messages
22
I have a folder on my desktop with a bunch of subfolders by peoples names (i.e. Subfolder1 = DOE, JOHN; Subfolder2 = SMITH, JOHN, etc.). When I change cell "B2" in the spreadsheet and run the Macro, I would like it to save that sheet as a .pdf to the applicable person's folder that is listed in "B2". Then, when I change names and run it again, it will save it to the next persons folder.

Thanks for any help!

here is what I currently have.

Code:
Sub GeneratePDF()
Dim Path As String
Dim Filename As String

Call SetPrintArea
Path = "K:\10 Quality Assurance\04 Inspection Stamp Log and Authority\03 Weld & Braze Certification Logs" & "\" & ActiveSheet.Range("B2").Value
Filename = ActiveSheet.Range("B3").Value & "-" & ActiveSheet.Range("D3").Value
Application.DisplayAlerts = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & " " & ActiveSheet.Range("B3").Value & "-" & ActiveSheet.Range("D3").Value & "-" & ActiveSheet.Range("F3").Value & ".pdf"
Application.DisplayAlerts = True

End Sub

Sub SetPrintArea()
    Range("A2:G14").Select
End Sub

Function FolderExists(FolderPath As String) As Boolean
On Error Resume Next

ChDir FolderPath
If Err Then FolderExists = False Else FolderExists = True

End Function
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Currently, the macro is saving the PDF to the main folder (K:\10 Quality Assurance\04 Inspection Stamp Log and Authority\03 Weld & Braze Certification Logs)
but does not go into the subsequent subfolder that matches Cell B2. I just need it to go one step further.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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