MrKhoa3108
Thành viên mới
- Tham gia
- 22/10/13
- Bài viết
- 25
- Được thích
- 4
Mã:
Sub LinkHinh()
Dim pathFile, photo, FOLDER As String
Dim cntRow As Double
Dim fldr As FileDialog
Dim photoCol As Integer
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub
FOLDER = .SelectedItems(1)
End With
cntRow = 2
Do While Cells(cntRow, 1).Value <> Empty
photoCol = 5
If Cells(cntRow, photoCol).Value = Empty Then
'base on respondID
photo = Dir(FOLDER & "\*" & Range("A" & CStr(cntRow)).Value & "*")
Do While photo <> vbNullString
pathFile = FOLDER & "\" & photo
ActiveSheet.Hyperlinks.Add Cells(cntRow, photoCol), pathFile, , , "Photo"
photo = Dir
photoCol = photoCol + 1
Loop
End If
cntRow = cntRow + 1
Loop
MsgBox "Done!!!"
End Sub
-Đính kèm file code và file anh để mọi người cùng thử
link ảnh mẫu : https://drive.google.com/file/d/1ijhQ509sdk2IulbtOPPACBDBCcOPAFiO/view?usp=sharing