• 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
    

      

  • 相关阅读:
    [最短路-Floyd][并查集]SSL P2344 刻录光盘
    [并查集][bfs]JZOJ P3973 黑白数
    [容斥原理][dp]JZOJ P3056 数字
    [归并排序][枚举]JZOJ P3967 Counting Friends
    [二分][贪心]JZOJ P3996 Sabotage
    [最短路-Floyd][数学]Luogu P1552 牛的旅行
    [序列dp]Luogu P1415 拆分数列
    [多项式求逆]JZOJ 3303 城市规划
    [树链剖分]JZOJ 2677 树A
    [费用流]luogu P3159 交换棋子
  • 原文地址:https://www.cnblogs.com/nextseven/p/7488450.html
Copyright © 2020-2023  润新知