Sep 01 2021 12:12 AM
Hi All, can someone please assist with the following VBA code. I added the button to save the worksheet as pdf to a specific folder, I would like to add a date stamp to the filename when saving. Example: Employee name 202108.pdf
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\Users\Documents\Sample.pdf", _
OpenAfterPublish:=True
Application.ScreenUpdating = True
End Sub
Sep 01 2021 01:19 AM
SolutionFor example:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\Users\Documents\Sample_" & Format(Now, "yyyymmdd_hhmmss") & ".pdf", _
OpenAfterPublish:=True
Application.ScreenUpdating = True
End Sub
Remark: characters such as / and : are not allowed in file names, hence the use of the Format function.
Sep 01 2021 02:07 AM
Jan 10 2022 06:29 AM
Jan 10 2022 06:43 AM
Jan 10 2022 07:04 AM
Good to hear that you found the solution.
Sep 01 2021 01:19 AM
SolutionFor example:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\Users\Documents\Sample_" & Format(Now, "yyyymmdd_hhmmss") & ".pdf", _
OpenAfterPublish:=True
Application.ScreenUpdating = True
End Sub
Remark: characters such as / and : are not allowed in file names, hence the use of the Format function.