20170907wdVBA_ImportPicturesBaseOnExcel
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的更多相关文章
随机推荐
- android studio设计模式和文本模式切换
- python --- 20 约束 异常处理 MD5 日志
一.类的约束 1.抛出异常 NotImplementedError 2.抽象方法 含有抽象方法的类是抽象类 抽象类中的方法全是抽象方法的是接口 抽象类不能创建对象 二.异常处理 处理完后代码可继 ...
- 自动化测试系列:Selenium UI自动化解决iframe定位问题
更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/6735116.html 一个阴雨霏霏 ...
- 流程控制if,while,for
if语句 什么是if语句 判断一个条件如果成立则做...不成立则做....为何要有if语句 让计算机能够像人一样具有判断的能力 如何用if语句 语法1: if 条件1: code1 code2 cod ...
- Android系统更新防互刷功能实现与分析【转】
本文转载自:https://blog.csdn.net/huangyabin001/article/details/44465145 版权声明:本文为博主原创文章,未经博主允许不得转载. htt ...
- 集训总结DAY.1(18.5.22)——KMP
DAY 1——5.22 in the morning 依稀记得我们有一场contest. at night chf大佬讲KMP,先膜一波~~~ luoguP3375KMP模板题 KMP算法,又称模式匹 ...
- ZOJ 3829 Known Notation(贪心)题解
题意:给一串字符,问你最少几步能变成后缀表达式.后缀表达式定义为,1 * 1 = 1 1 *,题目所给出的字串不带空格.你可以进行两种操作:加数字,交换任意两个字符. 思路:(不)显然,最终结果数字比 ...
- (zhuan) 大牛讲堂 | 算法工程师入门第二期-穆黎森讲增强学习
大牛讲堂 | 算法工程师入门第二期-穆黎森讲增强学习 2017-07-13 HorizonRobotics
- slot是标签的内容扩展,也就是说你用slot就可以在自定义组件时传递给组件内容,组件接收内容并输出
html 父页面<div id="app"> <register> <span slot="name">{{message. ...
- Linux 下上手 STC89C52RC
第一次接触单片机,自然选择了简单的51单片机.然而我的操作系统是 Linux .在 Windows 下上手51似乎很容易.但是 Linux 上搭建 51 开发环境不是很顺. 那么谈谈 Linux 我如 ...