I'm very new to VBA and programming and so I have no real idea how I can get around this problem that I have. Any help would be greatly appreciated! Sorry if it's difficult to understand exactly what I'm trying to do. If you need clarification on anything I will be online to answer any questions straight away.
Context: I have a spreadsheet that contains a list of employee names and their certifications. I want to be able to assign a button to each employee in column B with a macro that is able to zip files from a folder that contains that employees name.
The following code assigns buttons to each employee in column B. At the moment the code I have is able to assign the macro "Zip" to each button.
The following code is my Zip macro:
....
Now, this Zip macro is able to zip the file for the employee "Anthony Tran". However I need it to be able to recognise which employee's button I've clicked and search the same files as above except with that employees name instead of "Anthony Tran".
If it makes things easier, the code for creating buttons for each employee is able to name that button as the employees name that it represents.
Context: I have a spreadsheet that contains a list of employee names and their certifications. I want to be able to assign a button to each employee in column B with a macro that is able to zip files from a folder that contains that employees name.
The following code assigns buttons to each employee in column B. At the moment the code I have is able to assign the macro "Zip" to each button.
Code:
Dim Btn As Button
Dim rng As Range
For I = 2 To RowCount + 1
With Worksheets("Sheet1")
Set rng = .Range("B" & I)
Set Btn = .Buttons.Add(rng.Left, rng.Top, rng.Width, rng.Height)
With Btn
.Name = Range("B" & I) ' Names button as employee name
.Caption = Range("B" & I) ' Employee name appears on button as text
.OnAction = "Zip" ' Assigns macro "Zip" to each button
End With
End With
The following code is my Zip macro:
Code:
Sub Zip()
Dim strDate As String, SavePath As String, sFName As String
Dim oApp As Object, iCtr As Long, I As Integer
Dim vArr, FileNameZip
Dim FName() As Variant
SavePath = "C:\Users\MDuff3\Desktop\" 'save zip location
strDate = Format(Now, " dd-mmm-yy h-mm-ss")
FileNameZip = SavePath & "Anthony Tran " & strDate & ".zip"
FName = Array("Y:\Administration\Personnel\Certifications And Identification\CSTP\Anthony Tran_CSTP.pdf\", _
"Y:\Administration\Personnel\Certifications And Identification\Dangerous Goods Security Cards\Anthony Tran_DGSC_08-Mar-2017.pdf\", _
"Y:\Administration\Personnel\Certifications And Identification\DG Transportation Training\DGBR\Anthony Tran_DGBR_30-Oct-2014.pdf\", _
"Y:\Administration\Personnel\Certifications And Identification\Working at Height\Anthony Tran_WorkingAtHeights.pdf\", _
"Y:\Administration\Personnel\Certifications And Identification\Licence to use Radioactive Material-Engineer\Anthony Tran_RA_10-Feb-2015.pdf\", _
"Y:\Administration\Personnel\Certifications And Identification\HUET Course Cards\Anthony Tran_HUET_03-Sep-2015_BOSIET.pdf\")
Now, this Zip macro is able to zip the file for the employee "Anthony Tran". However I need it to be able to recognise which employee's button I've clicked and search the same files as above except with that employees name instead of "Anthony Tran".
If it makes things easier, the code for creating buttons for each employee is able to name that button as the employees name that it represents.
Last edited: