点击这里查看首页

WORD批量插入图片和文件名


来源:网络整理
发布时间:2019-11-12 10:42:00
查看次数:

内容提要:因为需要,找了两个VBA代码。


另一个
Sub InsertPic()
    Dim myfile As FileDialog
    Set myfile = Application.FileDialog(msoFileDialogFilePicker)
    With myfile
        .InitialFileName = "F:"
        If .Show = -1 Then
            For Each fn In .SelectedItems

                Set mypic = Selection.InlineShapes.AddPicture(FileName:=fn, SaveWithDocument:=True)
                '按比例调整相片尺寸
                WidthNum = mypic.Width
                c = 10         '在此处修改相片宽,单位厘米
                mypic.Width = c * 28.35
                mypic.Height = (c * 28.35 / WidthNum) * mypic.Height
                If Selection.Start = ActiveDocument.Content.End - 1 Then  '如光标在文末
                    Selection.TypeParagraph    '在文末添加一空段
                Else
                    Selection.MoveDown
                End If
                Selection.Text = Basename(fn)    '函数取得文件名
                Selection.EndKey

                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, 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


转载自:http://club.excelhome.net/forum.php?mod=viewthread&tid=778982&page=1#pid5315103

第1页 第2页

相关文章
·Word轻松排版四步曲 08-30
·PS如何一键批量裁剪图片?06-02
·一步去掉页眉横线的方法08-02
·开机提示ntldr is missing解决方法08-13
·视频号视频的四种下载方法07-07
·Excel随机生成区间数值06-23
·怎么用Microsoft Excel排名次03-12
·使用光影魔术手修改相片格式教程10-29
·微信公众号音频音乐提取方法10-19
·视频加速脚本TimerHooker (计时器掌控者)06-17
最新文章
·2026年广东继续公需课学习05-31
·安装油猴(篡改猴)脚本05-21
·如何一键关闭全校所有一体机01-20
·新版希沃白板5不登录账号就能写板书的解决方法01-13
·3个Word中英文排版问题10-25
·你还在逐字修改文章?这8个AI提示词,让你改稿效率翻10-18
·双语阅读︱用这个方法,微信存储一下释放好几个G!09-20
·IDM is corrupt 错误弹窗怎么解决?09-17
·一列数据轻松转换成多行多列02-05
·MPC-HC如何加速播放不变音调?01-06
阅读排行