Word 批量插入图片:显示文件名

Sub 插入二维码图片()
    '
    ' 插入二维码图片 宏
    '
    '
    Dim myfile As FileDialog
    Set myfile = Application.FileDialog(msoFileDialogFilePicker)

    With myfile
        .InitialFileName = "D:\2020-02-29\"

        If .Show = -1 Then

            a = 1 '循环次数

            For Each fn In .SelectedItems

                Set mypic = Selection.InlineShapes.AddPicture(FileName:=fn, SaveWithDocument:=True)
                mypic.Width = 200  '根据需要设置,1cm = 28.35px
                mypic.Height = 200
                If Selection.Start = ActiveDocument.Content.End - 1 Then  '如光标在文末
                Selection.TypeParagraph '在文末添加一空段
            Else
                Selection.MoveDown
            End If

            Selection.MoveDown

            Selection.Text = Basename(fn)    '函数取得文件名
            Selection.EndKey
            'Selection.TypeParagraph '文字后面添加一空段

            If Not (a Mod 3 = 0) Then
                Selection.TypeParagraph '文字后面添加一空段
            End If

            'MsgBox (a)
            a = a + 1

            If Selection.Start = ActiveDocument.Content.End - 1 Then  '如光标在文末
            Selection.TypeParagraph '在文末添加一空段
        Else
            Selection.MoveDown
        End If

    Next fn

Else
End If

End With

Set myfile = Nothing
End Sub

Function Basename(FullPath) '取得文件名
Dim x
Dim y
Dim tmpstring
tmpstring = FullPath
x = Len(FullPath)

For y = x To 1 Step -1

If Mid(FullPath, y, 1) = "\" Or _
    Mid(FullPath, y, 1) = ":" Or _
    Mid(FullPath, y, 1) = "/" Then
    tmpstring = Mid(FullPath, y + 1)
    Exit For
End If

Next

Basename = Left(tmpstring, Len(tmpstring) - 4)

End Function