Public Sub ImportPicturesBaseOnExcel()

    Dim shp As Object
Dim xlApp As Object
Dim Wb As Object
Dim Rng As Object
Dim FolderPath As String
Dim ImgFolder As String
Dim ExcelPath As String
Dim FilePath As String
Const ExcelFile As String = "身份证号.xls" FolderPath = ThisDocument.Path & "\"
ExcelPath = FolderPath & ExcelFile
ImgFolder = FolderPath & "照片\" On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If xlApp Is Nothing Then
Set xlApp = CreateObject("Excel.Application")
End If
On Error GoTo 0 Set Wb = xlApp.workbooks.Open(ExcelPath)
EndRow = Wb.worksheets(1).Range("A65536").End(3).Row
Set Rng = Wb.worksheets(1).Range("A2:A" & EndRow)
arr = Rng.Value
Wb.Close
xlApp.Quit If ThisDocument.InlineShapes.Count > 0 Then
For Each shp In ThisDocument.InlineShapes
shp.Delete
Next shp
End If
If ThisDocument.Shapes.Count > 0 Then
For Each shp In ThisDocument.Shapes
shp.Delete
Next shp
End If Selection.WholeStory
Selection.Delete
Selection.HomeKey wdStory
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter For i = LBound(arr) To UBound(arr)
FilePath = ImgFolder & "*" & arr(i, 1) & "*.jpg"
Debug.Print FilePath
FileName = Dir(FilePath)
If FileName <> "" Then FilePath = ImgFolder & FileName
n = n + 1
For j = 1 To 2
Set shp = ThisDocument.InlineShapes.AddPicture(FileName:=FilePath, _
LinkToFile:=False, SaveWithDocument:=True)
Selection.Collapse wdCollapseEnd
Next j If n Mod 2 = 0 And n Mod 8 <> 0 Then
Selection.EndKey wdStory
Selection.TypeParagraph
End If
If n Mod 8 = 0 Then
Selection.EndKey wdStory
Selection.InsertBreak Type:=wdPageBreak
End If End If
Next i Set shp = Nothing
End Sub

  

20170907wdVBA_ImportPicturesBaseOnExcel的更多相关文章

随机推荐

  1. 回归Android之Android基础和小常识

    Activity ,Service,Content Provider,BroadcastReceiver, Intent SQLite,Http,Fragement,Handle 1,Activity ...

  2. Junit 的Assertions的使用

    import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.anyOf; import ...

  3. Python3基础 list list()生成空列表

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  4. Python3基础 dict clear 清空一个字典

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  5. 解决/var/log下没有messages文件的问题?

    fedora23和centos7+ 都是使用的 systemd 来代替sysv 管理系统启动和服务了. 在systemd 中主要包含两个方面的内容, 当打开/etc/inittab 文件时, 会看到: ...

  6. FJUT3591 侦测到在途的聚变打击(最小不可相交路径覆盖)题解

    题意:给你n个点,点间m条路,给出在每条路要走的时间.现在有q个任务,要摧毁q个点,每次提供ci和ti表示在时间ti摧毁点ci(必须正好在时间ti才能摧毁),每个点可能需要多次摧毁(同一时间能在同一个 ...

  7. JavaWeb--简单分页技术

    分页需要的技术点:1.前台分页标签的使用 2.前台上一页,下一页显示的业务逻辑 3.MSQL用到的语句  limit 4.封装pageBean对象 这个是PageBean用到的 分页公式: int t ...

  8. Java中常用的方法

    枚举: 1:DemoEnum.valueOf(String str) 从枚举类中中找字符串,如果有则返回对应枚举值 2:DemoEnum.values() 获得枚举集合 3:DemoEnum.prop ...

  9. @PathVariable与@RequestBody的区别,及前段请求接口的写法。

    @PathVariable 1:接受参数时,地址栏为:/{args1}/{args2} 2:用法:(@PathVariable(value = "args")Long  id) 3 ...

  10. Git、GitHub、GitLab三者之间的联系以及区别

    在讲区别以及联系之前先简要的介绍一下,这三者都是什么(本篇文章适合刚入门的新手,大佬请出门左转) 1.什么是 Git? Git 是一个版本控制系统. 版本控制是一种用于记录一个或多个文件内容变化,方便 ...