VBA/Excel/Access/Word/Data Type/OLEObject — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 15:48, 26 мая 2010
Creating Compound Documents Programmatically Using OleObjects
<source lang="vb">
Sub CreateCompoundDocument()
Dim rg As range Dim obj As OLEObject Set rg = ThisWorkbook.Worksheets(1).Cells(2, 2) Set obj = InsertObject(rg, "C:\testdoc.doc", False) If Not obj Is Nothing Then Debug.Print "Object inserted." Else Debug.Print "Sorry - the object could not be inserted." End If Set obj = Nothing Set rg = Nothing
End Sub Function InsertObject(rgTopLeft As range, sFile As String, bLink As Boolean) As OLEObject
Dim obj As OLEObject On Error GoTo ErrHandler Set obj = rgTopLeft.Parent.OLEObjects.add(FileName:=sFile, Link:=bLink) obj.Top = rgTopLeft.Top obj.Left = rgTopLeft.Left Set InsertObject = obj Exit Function
ErrHandler:
Debug.Print Err.Description Set InsertObject = Nothing
End Function
</source>