FileNumber Property

See Also1JOTHJN              Example1AYFRZP>Low

Applies To

OLE control2HQDVVU.

Description

Determines the file number to be used when saving or loading an OLE object, or reflects the last file number used.  Not available at design time.

Usage

[form.]ole.FileNumber [ = filenumber ]

Remarks

The FileNumber must correspond to an open, binary file.

Use this property to specify the number of the file to be opened or saved when setting Action = 11 (Save) or Action = 12 (Read).

Data Type

IntegerDOKXHY


See Also

Help:

Action Property04T78S3

FreeFile FunctionUU1FR

Open Statement103I7PS

 

Programmer's Guide:

Chapter 22, "Object Linking and Embedding (OLE)"


FileNumber Property Example

The example shows how to save and open the data associated with Ole1 in a file named MYOB.OLE.  To run the example you need Microsoft Excel 4.0 running or on your path.  Create a form with an OLE control named Ole1.  When the Insert Object dialog is displayed, press Cancel.  Place a command button named Command1 on the form.  Place a menu named File on the form with two menu items: mnuOpenObject and mnuSaveObject.

Press F5 and then press the command button to set the Class and Action properties.  Microsoft Excel starts if it is not already running.  Enter data in a spreadsheet, then choose Update from the Microsoft Excel File menu to show the data in the OLE control.  Choose Save from the example form's File menu.  This creates the file in which the OLE object is saved.  You can end the example application, start it again and choose Open Object from its File menu to display the object independently of Microsoft Excel.  Note that when you do so, the command button is disabled.

Sub Command1_Click ()
   Ole1.Class = "ExcelWorksheet"         ' Set class.
   Ole1.Action = 0                       ' Create OLE object.
   Show                                  ' Show form with object,
   Command1.Enabled = False              ' then disable button.
End Sub


Sub mnuSaveObject_Click ()
   Dim FileNum                           ' Declare variable.
   FileNum = FreeFile                    ' Get a valid file number.
   Open "MYOB.OLE" For Binary As FileNum ' Open file to be saved.
   Ole1.FileNumber = FileNum             ' Set the filenumber.
   Ole1.Action = 11                      ' Save the file.
   Close #FileNum                        ' Close the file.
End Sub


Sub mnuOpenObject_Click ()
   Dim FileNum                           ' Declare variable.
   FileNum = FreeFile                    ' Get a valid file number.
   Open "MYOB.OLE" For Binary As FileNum ' Open the file.
   Ole1.FileNumber = FileNum             ' Set the filenumber.
   Ole1.Action = 12                      ' Get data from file.
   Close #FileNum                        ' Close the binary file.
' Since you've opened the file, disable button that initiates object.
   Command1.Enabled = False
End Sub