|
试试:
- Sub GetPic()
- Dim fth, fld, drv As Object, pth
- On Error Resume Next
- Application.ScreenUpdating = False
- fth = ThisDocument.Path
- Set obMapp = CreateObject("Shell.Application").BrowseForFolder(0, stMedd, fth) '&H1
- If Not obMapp Is Nothing Then
- fld = CreateObject("scripting.filesystemobject").GetFolder(fth).SubFolders
- For Each drv In CreateObject("scripting.filesystemobject").GetFolder(fth).SubFolders
- pth = fth & "" & drv.Name
- Call PictoWord(pth, ".jpg")
- Next
- End If
- MsgBox "ok!"
- Application.ScreenUpdating = True
- End Sub
- Function PictoWord(ByVal wpth As String, ByVal hj As String)
- Dim wd, i As Long, n As Long, f
- On Error Resume Next
- Application.ScreenUpdating = False
- Set wd = CreateObject("word.application")
- Set wd = Documents.Add
- With Selection.PageSetup
- .LineNumbering.Active = False
- .Orientation = wdOrientPortrait
- .TopMargin = CentimetersToPoints(2.5)
- .BottomMargin = CentimetersToPoints(2.5)
- .LeftMargin = CentimetersToPoints(3)
- .RightMargin = CentimetersToPoints(3)
- .Gutter = CentimetersToPoints(0)
- .HeaderDistance = CentimetersToPoints(1.5)
- .FooterDistance = CentimetersToPoints(1.75)
- .PageWidth = CentimetersToPoints(21)
- .PageHeight = CentimetersToPoints(29.7)
- .FirstPageTray = wdPrinterDefaultBin
- .OtherPagesTray = wdPrinterDefaultBin
- .SectionStart = wdSectionNewPage
- .OddAndEvenPagesHeaderFooter = False
- .DifferentFirstPageHeaderFooter = False
- .VerticalAlignment = wdAlignVerticalTop
- .SuppressEndnotes = False
- .MirrorMargins = False
- .TwoPagesOnOne = False
- .BookFoldPrinting = False
- .BookFoldRevPrinting = False
- .BookFoldPrintingSheets = 1
- .GutterPos = wdGutterPosLeft
- .CharsLine = 45
- .LinesPage = 46
- .LayoutMode = wdLayoutModeLineGrid
- End With
- ActiveDocument.Paragraphs.Format.Alignment = wdAlignParagraphCenter
- Selection.TypeText Text:=Split(wpth, "")(UBound(Split(wpth, ""))) & " - 户口本" & vbLf
- Selection.TypeText Text:=Format(Now(), "yyyy-mm-dd") & vbLf & vbLf
-
- f = Dir(wpth & "\*" & hj)
- Do While f <> ""
- If InStr(f, hj) Then
- Set mypic = Selection.InlineShapes.AddPicture(FileName:=wpth & "" & f, SaveWithDocument:=True)
- mypic.Width = CentimetersToPoints(7.5)
- mypic.Height = CentimetersToPoints(5.5)
- Selection.Range.ParagraphFormat.Reset
- Selection.Range.Paragraphs.Alignment = wdAlignParagraphCenter
- Selection.InsertAfter vbLf
- End If
- f = Dir()
- Loop
- Selection.InsertAfter Text:="县教育局" 'ActiveDocument.Content.InsertAfter Text:="县教育局"
- wd.SaveAs FileName:=wpth & "" & Split(wpth, "")(UBound(Split(wpth, ""))) & ".doc"
- wd.Close
- wd.Quit
- 'Dim sCmd As String
- 'sCmd = "cmd /c Taskkill /im winword.exe /f /t" '强制关闭word进程
- 'Shell sCmd
- Set wd = Nothing
- Application.ScreenUpdating = True
- End Function
复制代码
运行 GetPic |
|