Forum Discussion
mydataismeaningless
Nov 22, 2021Copper Contributor
Export to PDF Macro Naming issue XLOOKUP of firstname&&" "&lastname
Hello there, I have a macro that exports to PDF down a list of employees. I can successfully export each report with the employee ID in the filename, but I'm trying to add the full name as well. ...
- Nov 22, 2021
Hi, try this. I just added a nameID string that works the same way lngID works and gets called into the PDF export. Can't perfectly test without the workbook but let me know what works and what doesn't and we can narrow it down more!
Sub OGExport2PDF() Dim wshReport As Worksheet, wshData As Worksheet Dim lngRow As Long, lngLastRow As Long, lngID As Long Dim strPath As String, nameID As String Application.ScreenUpdating = False Set wshReport = Worksheets("Total Comp & Benefits Statement") Set wshData = Worksheets("Salary and Benefits") strPath = ThisWorkbook.Path & Application.PathSeparator lngLastRow = wshData.Range("D" & wshData.Rows.Count).End(xlUp).Row For lngRow = 3 To lngLastRow lngID = wshData.Range("D" & lngRow).Value nameID = wshData.Range("B" & lngRow).Value wshReport.Range("D4").Value = lngID wshReport.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strPath & lngID & "_" & nameID & ".pdf" Next lngRow Application.ScreenUpdating = True End Sub
HansVogelaar
Nov 22, 2021MVP
See Finding a way to generate "report" exports (PDF) down a list of ID's where you also asked this.