Share via


DocumentFile Property

Returns the name of the file from which a linked OLE object was created. At design time, specifies the name of the linked file. Read-only at design time and run time for an existing object, but can be set for an object when creating it.

Object.DocumentFile[ = cFileName]

Property Values

  • cFileName
    The name of the file to which the object is linked. The name includes the full path of the file.

Remarks

DocumentFile contains the empty string for embedded (not linked) objects.

You set the DocumentFile property of a linked OLE object using the Insert Object dialog box when you initially add an OLE container to a form. You can also set this property when creating an OLE object using the APPEND GENERAL command or when defining the object in code as part of a class definition.

Before specifying the contents of an OLE object using the DocumentFile property, specify the Automation server application by setting the object's OLEClass.

Example

The following example adds an OLE Container control to a form, and uses the DocumentFile and OleClass properties to specify a Microsoft Excel worksheet as the file to edit and Microsoft Excel as the Automation server.

The DocumentFile property specifies a worksheet named Book1.xls in the EXCEL directory on drive C. This example will not work properly if the file and directory specified in the DocumentFile property do not exist; it may be necessary to modify the DocumentFile property to specify an existing directory and worksheet file.

The DoVerb method is used to activate the worksheet for editing.

frmMyForm = CREATEOBJECT('form')  && Create a form
frmMyForm.Closable = .F.  && Disable the Control menu box

frmMyForm.AddObject('cmdCommand1','cmdMyCmdBtn')  && Add Command button
frmMyForm.AddObject("oleObject","oleExcelObject")  && Add OLE object

frmMyForm.cmdCommand1.Visible=.T.  && Display the "Quit" Command button

frmMyForm.oleObject.Visible=.T.  && Display the OLE control
frmMyForm.oleObject.Height = 50  && OLE control height

frmMyForm.Show  && Display the form

frmMyForm.oleObject.DoVerb(-1)  && -1 for Edit

READ EVENTS  && Start event processing

DEFINE CLASS oleExcelObject as OLEControl
   OleClass ="Excel.Sheet"  && Server name
   DocumentFile = "C:\EXCEL\BOOK1.XLS"  && This file must exist 
ENDDEFINE

DEFINE CLASS cmdMyCmdBtn AS CommandButton  && Create Command button
   Caption = '\<Quit'  && Caption on the Command button
   Cancel = .T.  && Default Cancel Command button (Esc)
   Left = 125  && Command button column
   Top = 210  && Command button row
   Height = 25  && Command button height

   PROCEDURE Click
      CLEAR EVENTS  && Stop event processing, close form
ENDDEFINE

See Also

APPEND GENERAL | CREATEOBJECT( ) | OLEClass

Applies To: OLE Bound Control | OLE Container Control