VBA Help

johns99

Board Regular
Joined
Jun 11, 2013
Messages
223
Office Version
  1. 365
Platform
  1. Windows
Hello, I'm currently using the following VBA to save files from a list of employee IDs to PDF files. Currently, the coding is saving the files with the employee IDs, but I'd like to change this to the employee names. Does anyone know what I need to do to update the below?


'Declare variables
Dim ws As Worksheet
Dim rngID As Range
Dim rngListStart As Range
Dim rowsCount As Long
Dim i As Long
Dim pdffilepath As String
Dim tempPdfFilePath As String

'Stop screen updating during running
Application.ScreenUpdating = False


'Reference the Report Sheet
Set ws = ActiveWorkbook.Sheets("Sample Statement")

'Reference Employee ID cell
Set rngID = ws.Range("G5")


'Reference the start of the employee list
Set rngListStart = ws.Range("Q10")

'Refeence the pdfFilePath
pdffilepath = "W:\Long Term Incentive Awards\PAYOUTS\2013 OICP\2024 January RSU Vestings\US Employees\STATEMENTS\LTI Vesting Statement - [ID].pdf"

'Count the number of employee ID
rowsCount = rngListStart.CurrentRegion.Rows.Count - 1

For i = 1 To rowsCount


'Change the current employee ID
rngID.Value = rngListStart.Offset(i - 1, 0).Value

'Replace [ID] with the current employee ID
tempPdfFilePath = Replace(pdffilepath, "[ID]", rngID.Value)

'Create the PDFs
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=tempPdfFilePath

Next i

'Restart screen updating during running
Application.ScreenUpdating = True


End Sub
 
this will get your fullname

Dim fullName As String
fullName = rngListStart.Rows(i).Offset(, 1).Value
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
This isn't working unfortunately

I'm getting the following error

1705425416464.png
 
Upvote 0
If I'm only doing the last name and the list starts in R1 is the below correct?

Dim ws As Worksheet
Dim rngID As Range
Dim rngListStart As Range
Dim rowsCount As Long
Dim i As Long
Dim pdffilepath As String
Dim tempPdfFilePath As String

'Stop screen updating during running
Application.ScreenUpdating = False


'Reference the Report Sheet
Set ws = ActiveWorkbook.Sheets("Sheet1")

'Reference Employee ID cell
Set rngID = ws.Range("G5")

'Reference the start of the employee list
Set rngListStart = ws.Range("Q10")

'Refeence the pdfFilePath
pdffilepath = "W:\Long Term Incentive Awards\PAYOUTS\2013 OICP\2024 January RSU Vestings\US Employees\STATEMENTS\LTI Vesting Statement - [ID].pdf"

'Count the number of employee ID
rowsCount = rngListStart.CurrentRegion.Rows.Count - 1

For i = 1 To rowsCount

'Change the current employee ID
rngID.Value = rngListStart.Offset(i - 1, 0).Value

'Replace [ID] with the current employee ID
' get the first/last name
Dim fullName As String

fullName = rngListStart.Rows(i).Offset(, 1).Value
tempPdfFilePath = Replace(pdffilepath, "[ID]", fullName)

'Create the PDFs
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=tempPdfFilePath

Next i

'Restart screen updating during running
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Yes, that Looks correct. You need a
Pubic Sub CreateReport to start the sub procedure
 
Upvote 0
Disregard my last, I removed the old macro and replaced with the above and all is good, thank you so much! This was excellent!
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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