· 8 years ago · Jan 03, 2018, 10:22 AM
1'Put this in your module
2
3Sub PutLinksInACell()
4 Dim rangeAddress As String
5 Dim fileArray
6 fileArray = Array("144234SDFsdf0fghf10_144234.pdf", "144234ghfrg35bzb-20-1_R04.docx", "144234xcvbebeEN 113.pdf")
7 'rangeAddress = Selection.Cells(1, 1).Address(RowAbsolute:=False, ColumnAbsolute:=False)
8 insertPicture Application.ActiveWorkbook.Path & "link.png", "A1", fileArray
9End Sub
10
11Sub insertPicture(picpath As String, cellAddress As String, fileArray As Variant)
12 '----------------------------------------------------------------------------
13 ' "THE BURGER-WARE LICENSE" (Revision 42):
14 ' <abybaddi009 gmail.com> wrote this code. As long as you retain this notice you
15 ' can do whatever you want with this stuff. If we meet some day, and you think
16 ' this stuff is worth it, you can buy me a burger in return. ;-) -Abhishek Baddi
17 '----------------------------------------------------------------------------
18
19 Dim spacing As Long, size As Long
20
21 size = Range(cellAddress).Font.size
22 spacing = size * 0.2
23
24 x_coor = Range(cellAddress).Cells(1, 1).Left
25 y_coor = Range(cellAddress).Cells(1, 1).Top
26
27 For i = 1 To 3
28 ActiveSheet.Pictures.Insert(picpath).Select
29 With Selection
30 With .ShapeRange
31 .LockAspectRatio = msoTrue
32 .Height = size
33 End With
34 .Left = x_coor + 5
35 .Top = y_coor + size * (i - 1) + spacing * i
36 .Placement = 1
37 .PrintObject = True
38 End With
39
40 ActiveSheet.Hyperlinks.Add Anchor:=Selection.ShapeRange.Item(1), Address:= _
41 fileArray(i - 1)
42
43 Range(cellAddress).Select
44 Next
45 Range(cellAddress).HorizontalAlignment = xlLeft
46 Range(cellAddress).VerticalAlignment = xlTop
47End Sub