[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] 如何批量将文件夹内的图片导入word文档?

如何批量将文件夹内的图片导入word文档?              如:A文件夹内有多张jpg文件和一个word文件,如何批量操作将该文件夹内的所有jpg文件插入word文档

  1. Sub 批量插入图片()
  2.     Dim myfile As FileDialog
  3.     Set myfile = Application.FileDialog(msoFileDialogFilePicker)
  4.     Application.ScreenUpdating = False
  5.     With myfile
  6.         .InitialFileName = "D:\PicDir"
  7.         If .Show = -1 Then
  8.             For Each Fn In .SelectedItems
  9.                 Selection.Text = Basename(Fn)
  10.                 Selection.EndKey
  11.                 If Selection.Start = ActiveDocument.Content.End - 1 Then
  12.                     Selection.TypeParagraph
  13.                 Else
  14.                     Selection.MoveDown
  15.                 End If
  16.                 Set mypic = Selection.InlineShapes.AddPicture(FileName:=Fn, SaveWithDocument:=True)
  17.                 If Selection.Start = ActiveDocument.Content.End - 1 Then
  18.                     Selection.TypeParagraph
  19.                     Selection.TypeParagraph
  20.                 Else
  21.                     Selection.MoveDown
  22.                 End If
  23.             Next Fn
  24.         Else
  25.         End If
  26.     End With
  27.     Set myfile = Nothing
  28.     Application.ScreenUpdating = True
  29. End Sub
  30. Function Basename(FullPath)
  31.     Dim x, y
  32.     Dim tmpstring
  33.     tmpstring = FullPath
  34.     x = Len(FullPath)
  35.     For y = x To 1 Step -1
  36.         If Mid(FullPath, y, 1) = "\" Or _
  37.             Mid(FullPath, y, 1) = ":" Or _
  38.             Mid(FullPath, y, 1) = "/" Then
  39.             tmpstring = Mid(FullPath, y + 1)
  40.             Exit For
  41.         End If
  42.     Next
  43.     Basename = Left(tmpstring, Len(tmpstring) - 4)
  44. End Function
复制代码

TOP

回复 2# hfxiang 怎么用?

TOP

我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

回复 3# xiawj


    先打开word,之后Alt+F11->{插入->模块->[编辑:Ctrl+C & Ctrl+V]->Ctrl+s}->Alt+F8

TOP

返回列表