请参: Sub InsertPicture()
Dim XlObj As Excel.Application, XlWb As Excel.workbook, PicPath As String, MyPicture As Shape
On Error Resume Next
If Tasks.Exists("Microsoft Excel") = True Then '检查并建立EXCEL程序
Set XlObj = GetObject(, "Excel.Application")
Else
Set XlObj = CreateObject("Excel.Application")
End If
Set XlWb = XlObj.Workbooks.Open("d:\test.xls") ‘打开指定工作薄
PicPath = XlWb.Sheets(1).[a1].Value '设其值为“D:\personal\kingsoft\Powerword 2003\KingMS\Images\about.bmp"
Set MyPicture = ActiveDocument.Shapes.AddPicture(Anchor:=Selection.Range, FileName:=PicPath)
With MyPicture
.WrapFormat.Type = wdWrapSquare’文字环绕为四周型
.WrapFormat.AllowOverlap = False‘不允许重叠
End With
XlObj.Quit’关闭EXCEL程序
Set XlObj = Nothing
End Sub 请注意在VBA工程引用中勾选:”Microsoft Excel 10.0 object Library"(版本号不同10.0亦不同) |