|
你的模板没法用,参照模板要求写了个代码,测试结果基本符合你的要求,你看看,如果不行再做调整
Sub 提取照片()
Dim filesys As Object, drv As Object, fd As FileDialog, t As Table
Dim wd As Document, wd1 As Document, w$, s$, m$, n%, i%, a%, a1%, b%, b1%, d%, h%
Application.ScreenUpdating = False
Set filesys = CreateObject("scripting.filesystemobject")
Set fd = Application.FileDialog(4)
fd.AllowMultiSelect = True
fd.Show
On Error Resume Next
s = fd.InitialFileName
s1 = Replace(s, "照片", "结果")
For Each drv In filesys.GetFolder(s).SubFolders
If drv.Size > 0 Then
m = drv.Name
n = filesys.GetFolder(s & m & "\").Files.Count
Set wd = Documents.Add
With Selection
.Font.Name = "宋体"
.Font.Bold = True
.Font.Size = "12"
.Text = "七:现场照片等影像成果" & Chr(13)
.EndKey unit:=wdStory
End With
If n Mod 2 = 0 Then
If n = 2 Then
Set t = wd.Tables.Add(Selection.Range, 2, 1)
For i = 1 To 2
t.Range.Cells(i).Range.InlineShapes.AddPicture s & m & "\" & m & "_" & i & ".jpg"
wd.InlineShapes(i).LockAspectRatio = msoFalse
wd.InlineShapes(i).Height = CentimetersToPoints(11.11)
wd.InlineShapes(i).Width = CentimetersToPoints(14.62)
Next
Else
Set t = wd.Tables.Add(Selection.Range, n / 2, 2)
For i = 1 To n
t.Range.Cells(i).Range.InlineShapes.AddPicture s & m & "\" & m & "_" & i & ".jpg"
wd.InlineShapes(i).LockAspectRatio = msoFalse
wd.InlineShapes(i).Height = CentimetersToPoints(11.11)
wd.InlineShapes(i).Width = CentimetersToPoints(7.23)
Next
End If
Else
For i = 1 To n
If i = 1 Then
Selection.Range.InlineShapes.AddPicture s & m & "\" & m & "_" & i & ".jpg"
wd.InlineShapes(i).LockAspectRatio = msoFalse
wd.InlineShapes(i).Height = CentimetersToPoints(11.11)
wd.InlineShapes(i).Width = CentimetersToPoints(14.62)
Selection.EndKey unit:=wdStory
Selection.TypeText Chr(13)
Selection.EndKey unit:=wdStory
Set t = wd.Tables.Add(Selection.Range, 1, 2)
Else
t.Range.Cells(i - 1).Range.InlineShapes.AddPicture s & m & "\" & m & "_" & i & ".jpg"
wd.InlineShapes(i).LockAspectRatio = msoFalse
wd.InlineShapes(i).Height = CentimetersToPoints(11.11)
wd.InlineShapes(i).Width = CentimetersToPoints(7.23)
End If
Next i
End If
End If
wd.SaveAs2 (s1 & m & ".docx")
wd.Close
Next drv
Set fd = Nothing
Set filesys = Nothing
Application.ScreenUpdating = True
End Sub
|
|