I tried to use this VBA code to replace text (name of the image) with images but somehow this code only works on windows excel.
Always get N/A as the answer. Please kindly help
Sub InsertPicture()
Dim xPath As String
Dim xLastRow As Long
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "MosaicExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
xPath = "Macintosh HD/Users/davidhuy/Downloads/400"
If Right(xPath, 1) <> "\" Then xPath = xPath & "\"
xLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For Each Rng In WorkRng
If Rng.Value <> "" Then
If Dir(xPath & Rng.Value & ".jpg") <> "" Then
ActiveSheet.Pictures.Insert(xPath & Rng.Value & ".jpg").Select
With Selection.ShapeRange
.LockAspectRatio = msoFalse
.Left = Rng.Left
.Top = Rng.Top
.Width = Rng.Width
.Height = Rng.Height
End With
Rng.ClearContents
Else
Rng.Value = "N/A"
End If
End If
Next
Application.ScreenUpdating = True
End Sub
Bookmarks