1. 詳細(xì)步驟見(jiàn)
Excel單元格內(nèi)插入圖片(VBA創(chuàng)建函數(shù),根據(jù)圖片名稱批量插入)
2. VBA代碼部分改為如下代碼
Sub 插入圖形應(yīng)用()For Each shap In Sheet1.ShapesIf shap.Type <> 8 Then shap.DeleteNext shap Dim j As Long j = 2 'If Cells(1, 2) = "" Then Exit Sub '第一個(gè)就為空的話直接退出 Do Until j = Cells.Rows.Count If Cells(j, 1) <> "" Then Dim i As String i = "" If Len(Dir(ThisWorkbook.Path & "\圖庫(kù)\" & Cells(j, 1) & ".jpg")) Then i = ThisWorkbook.Path & "\圖庫(kù)\" & Cells(j, 1) & ".jpg" ElseIf Len(Dir(ThisWorkbook.Path & "\圖庫(kù)\" & Cells(j, 1) & ".png")) Then i = ThisWorkbook.Path & "\圖庫(kù)\" & Cells(j, 1) & ".png" End If If i <> "" Then Set rngs = Cells(j, 3) Sheet1.Shapes.AddPicture i, True, True, rngs.Left, rngs.Top, rngs.Width, rngs.Height End If End If j = j + 1 Loop End Sub
3. 實(shí)現(xiàn)效果如下