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的更多相关文章
随机推荐
- How to install Maven on Windows
			To install Apache Maven on Windows, you just need to download the Maven’s zip file, and Unzip it to ... 
- A>B等CSS选择器
			这些是CSS3特有的选择器,A>B 表示选择A元素的所有子B元素.与A B的区别在于,A B选择所有后代元素,而A>B只选择一代.另外:没有<的用法. A+B表示HTML中紧随A的B ... 
- Matconvnet 的一些记录
			Matconvnet 的一些记录 Example code from ADNet: Action-Decision Networks for Visual Tracking with Deep Rei ... 
- mybatis配置文件namespace用法总结
			本文为博主原创,未经允许不得转载: 由于在应用过程中,发现namespace在配置文件中的重要性,以及配置的影响,在网上看了很多博客,发现很多人对namespace存在误解, 所以总结一下namesp ... 
- JMeter 生成CSV文件中文变乱码的问题
			在通过BeanShell 生成CSV文件时,写入的中文字符默认情况会变成乱码. //默认情况生成的文件是asii编码.fileName = “c:\test.csv";fos = new F ... 
- WebStorm破解方法
			http://www.jianshu.com/p/85266fa16639 http://idea.lanyus.com/ webstorm 入门指南 破解方法 1. 下载的WebStorm http ... 
- python requests  post和get
			import requests import time import hashlib import os import json from contextlib import closing impo ... 
- Video 对象方法  canPlayType()
			<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ... 
- leetcode 29->   Divide Two Integers without using multiplication, division and mod operator
			class Solution(object): def divide(self, dividend, divisor): """ :type dividend: int ... 
- SqlServer中常常搞不清楚 sp_columns来看一看
			The sp_columns catalog stored procedure is equivalent to SQLColumns in ODBC. The results returned ar ... 
