Excel单元格内插入图片(VBA创建函数,根据图片名称批量插入,中间有空格)

1. 详细步骤见

Excel单元格内插入图片(VBA创建函数,根据图片名称批量插入)

2. VBA代码部分改为如下代码

Sub 插入图形应用()

For Each shap In Sheet1.Shapes

If shap.Type <> 8 Then shap.Delete

Next shap


    Dim j As Long

    j = 2

    'If Cells(1, 2) = "" Then Exit Sub   '第一个就为空的话直接退出

    Do Until j = Cells.Rows.Count

        If Cells(j, 1) <> "" Then
        
            Dim i As String
            
            i = ""
        
            If Len(Dir(ThisWorkbook.Path & "\图库\" & Cells(j, 1) & ".jpg")) Then

                i = ThisWorkbook.Path & "\图库\" & Cells(j, 1) & ".jpg"

            ElseIf Len(Dir(ThisWorkbook.Path & "\图库\" & Cells(j, 1) & ".png")) Then

                i = ThisWorkbook.Path & "\图库\" & Ce

你可能感兴趣的:(Excel,Excel,VBA,单元格批量插入图片)