|
- Sub 批量插入WORD对象()
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set SH1 = Worksheets("Sheet1")
-
- For Each SHAP In SH1.Shapes
- If SHAP.Type = msoEmbeddedOLEObject Then SHAP.Delete
- Next SHAP
-
- Dim RA As Range
- For I = 2 To SH1.Range("D65536").End(3).Row
- PathG = ThisWorkbook.Path & "" & SH1.Cells(I, 4).Value & ".docx" '//指定文件路径
-
- If FSO.FileExists(PathG) = True Then '//如果文件存在
- Rem 对象文件名,对象链接到该文件,图标或正常图片方式,指定图标文件,图标序号,图标下方显示一个标签
- Rem 指定位置和大小,图标就不会相互重叠 最后还有个括号
-
- Set RA = SH1.Range("E" & I)
- Set Obj = SH1.OLEObjects.Add(Filename:=PathG, Link:=True, DisplayAsIcon:=True _
- , IconFileName:=ThisWorkbook.Path & "\ICO.ICO", IconIndex:=0, IconLabel:=PathG _
- , Left:=RA.Left + 3 _
- , Top:=RA.Top + 3 _
- , Height:=SH1.Rows(RA.Row).RowHeight - 6 _
- , Width:=RA.Width - 6 _
- )
- With Obj
- .Select '//声明为:Obj 是为了可能的其他操作
- Rem 把行高改为与图标文件一样高,图标就不会相互重叠
- SH1.Rows(I).RowHeight = .Height + 6
- End With
- Else
- SH1.Cells(I, 5).Value = "没有此文件"
- End If
- Next I
- End Sub
复制代码 |
|