>** Instantiate Excel >oExcel = CREATEOBJECT("Excel.Application") > >** Open the workbook >oWorkbook = oExcel.Workbooks.Open(sFileName) > >** Get a reference to the sheet >oSheet = oExcel.Workbooks(1).ActiveSheet > >** Select all cells >oSheet.Cells.Select() > >** Autofit the cells >oSheet.Cells.EntireColumn.AutoFit() > >** Turn on auto filtering >IF NOT oSheet.AutoFilterMode > oExcel.Selection.AutoFilter >ENDIF > >** Save the changes >oWorkbook.Save() > >** Close the workbook and quit Excel >oWorkbook.Close() >oExcel.Quit() >>
oExcel.cells(1,1).activateOther than that, you do not need to make selection. Also I would recommend to avoid using references if you can proceed without them (or at least close them properly prior to closing Excel, otherwise you may have them hidden even after you close the program but they appear as Excel instances in the windows Task MAnager Process list):
oExcel = CREATEOBJECT("Excel.Application") WITH oExcel.Workbooks.Open(sFileName) WITH .ActiveSheet.usedrange .EntireColumn.AutoFit() IF NOT .parent.AutoFilterMode .AutoFilter ENDIF ENDWITH .Save() .Close() ENDWITH oExcel.Quit()Good Luck