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. String的getBytes()方法 以及 new String()

    在Java中,String的getBytes()方法是得到一个操作系统默认的编码格式的字节数组.这表示在不同的操作系统下,返回的东西不一样! String.getBytes(Stringdecode) ...

  2. SpringBoot Redis使用fastjson进行序列化

    在使用spring-data-redis,默认情况下是使用org.springframework.data.redis.serializer.JdkSerializationRedisSerializ ...

  3. C# 里调用vb的inputbox弹出窗

    https://blog.csdn.net/hutao1101175783/article/details/16800871 先对项目添加对Microsoft.VisualBasic的引用 Inter ...

  4. Luncene学习 第一天 《入门程序》

    整个luncene 流程 下面贴出代码 package com.zuoyan.lucene.demo; import java.io.File; import org.apache.commons.i ...

  5. 小文笔记 - phantomjs

    小文笔记 - phantomjs 视频推荐: http://www.intalesson.com/compedium/phantom 2017-05-13 第一节:安装 Windows安装: 下载解压 ...

  6. hihoCoder 1339 Dice Possibility(DP)

    http://hihocoder.com/problemset/problem/1339 题意: 求一个骰子扔n次后最后点数相加为m的概率. 思路: f[i][j]表示扔到第i次时总值为j的概率. # ...

  7. Tomcat 跨域问题的解决

    先下载CORS对应的Jar: 下载链接: https://download.csdn.net/download/u010739157/10565169 在tomcat的Web.xml中加上如下配置: ...

  8. 实现一个简单的flux

    前言 众所周知,React跟Flux是一对好基友. 其中,市场流行的Flux有Redux,Mobx,Reflux. 其中,用法最简单的是Reflux. 其数据流思路如下: +---------+ +- ...

  9. 初步:jenkins自动构建安卓Apk

    1:本地搭建jenkins 2:下载插件 3:配置相关信息(git,sdk等等) 3:拉取git仓库代码 4:编译执行 参考文章:http://www.cnblogs.com/reblue520/p/ ...

  10. 无损录制acestream直播流

    很多人选择用acestream收看一些频道,往往比较高清,但很多人不知道如何录制. 其实方法很简单,用ace自带的播放器播放后: 1.打开potplayer,右击->打开链接 2.把当前播放的a ...