| 因为OFFICE本身安全机制原因,只能通过插入菜单插入一个URL的文档,调用AddOLEObject方法不能指定FileName直接调用URL地址 出错信息如图:
  
 解决方案1:
 将URL文档保存到本机临时文件,在OFFICE中插入临时文件,最后删除产生的临时文件
 Sub InsertObj()
 
 Const adModeRead = 1
 Const adOpenIfExists = 33554432
 Const adOpenStreamFromRecord = 4
 Const adTypeBinary = 1
 Const adSaveCreateOverWrite = 2
 
 Dim oRec 'ADODB.Record
 Dim oStm 'ADODB.Stream
 
 Set oRec = CreateObject("ADODB.Record")
 Set oStm = CreateObject("ADODB.Stream")
 
 '从URL读取文档
 oRec.Open "aaaa.xls", "URL=http://localhost:81/document/upload/", adModeRead, adOpenIfExists
 
 ' 读取URL文档数据流
 oStm.Type = adTypeBinary
 oStm.Open oRec, adModeRead, adOpenStreamFromRecord
 oStm.SaveToFile "C:\a.xls", adSaveCreateOverWrite
 oStm.Close
 oRec.Close
 Set oStm = Nothing
 Set oRec = Nothing
 
 '拷贝到插入对象
 Selection.InlineShapes.AddOLEObject ClassType:="Package", FileName:= _
 "C:\a.xls", LinkToFile:=False, DisplayAsIcon:=False
 Kill "C:\a.xls"
 
 End Sub
 |