|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub test()
Dim wdApp As Object, wdDoc As Word.Document, strFileName$, strPath$
Dim ar, i&, strSaveName$, wdRange As Word.Range, shp As Shape, t#
strPath = ThisWorkbook.Path & "\"
strFileName = strPath & "如何把excel中c列的图片批量插入到word内乙方右边的格子中.docx"
If Dir(strFileName) = "" Then MsgBox "指定的文件不存在,请检查!", vbExclamation: Exit Sub
Application.ScreenUpdating = False
t = Timer
Set wdApp = CreateObject("Word.Application")
Set wdApp = GetObject(, "Word.Application")
If Err <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
With [A1].CurrentRegion
ar = .Value
Set wdDoc = wdApp.Documents.Open(strFileName)
Set wdRange = wdDoc.Content
For i = 2 To UBound(ar)
For Each shp In .Parent.Shapes
If shp.Type = msoPicture Then
If Abs((shp.Left + shp.Width / 2) - (.Cells(i, 3).Left + .Cells(i, 3).Width / 2)) < (shp.Width + .Cells(i, 3).Width) / 2 _
And Abs((shp.Top + shp.Height / 2) - (.Cells(i, 3).Top + .Cells(i, 3).Height / 2)) < (shp.Height + .Cells(i, 3).Height) / 2 Then
With wdApp.Documents.Add
strSaveName = strPath & ar(i, 1)
wdRange.Copy
wdApp.Selection.Paste
.tables(1).Range.Cells(2).Select
shp.Copy
wdApp.Selection.Paste
.SaveAs strSaveName
.Close
End With
Exit For
End If
End If
Next shp
Next i
wdDoc.Close False
End With
If Err <> 0 Then wdApp.Quit
Set wdApp = Nothing: Set wdDoc = Nothing: Set wdRange = Nothing
Application.ScreenUpdating = True
MsgBox "执行完毕!_用时: " & Format(Timer - t, "0.00") & " 秒", 64
End Sub
|
评分
-
1
查看全部评分
-
|