Programming methods for objects

A method for an object class is programmed by using a standard Sub or Function procedure placed in the class module. An object might or might not use methods. Your code executes a method using standard notation:

object.method

Like any other VBA method, a method that you write for an object class will perform some type of action. The following procedure is an example of a method that saves a workbook in one of two file formats, depending on the value of the XLFile variable. As you can see, there is nothing special about this procedure.

Sub SaveFile()

If XLFile Then

ActiveWorkbook.SaveAs FileName:=FName, _ FileFormat:=xlWorkbookNormal

Else

ActiveWorkbook.SaveAs FileName:=FName, _ FileFormat:=xlCSV

End If End Sub

The CSVFileClass example in the next section should clarify the concepts of properties and methods for object classes defined in a class module.

0 0

Post a comment