LPARAMETERS nFunction
LOCAL oleApp
IF PARAMETERS() = 0
        ** For populating data in the sheet
        nFunction   = 2
ENDIF
SELECT DISTINCT Table FROM tabledata INTO CURSOR tablenames
SELECT('tablenames')
nSheet  = 1
SCAN
        ** For renaming sheet name.
        IF nfunction = 1
                WAIT WINDOW "Renaming Sheet" + ALLT(STR(nSheet)) + "..." NOWAIT
                IF TYPE('OleSheet') <> 'O'
                        ** Get Current Instance
                        olesheet = GETOBJECT('c:\temp\tempsheet.xls')
                ENDIF
                oleapp = olesheet.Application
                with oleapp.worksheets(nSheet)
                        .name = ALLTRIM(TableNa