如何批量打印 带图片名字的图片?Word 宏命令

VB 专栏收录该内容
1 篇文章 0 订阅
Sub 插入二维码图片()
    '
    ' 插入二维码图片 宏
    '
    '
    Dim myfile As FileDialog
    Set myfile = Application.FileDialog(msoFileDialogFilePicker)

    With myfile
        .InitialFileName = "D:\"

        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



  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2022 CSDN 皮肤主题:Age of Ai 设计师:meimeiellie 返回首页

打赏作者

徐晓伟

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值