* Begin By Opening Excel
tmpsheet = CREATEOBJECT('excel.application')
oExcel = tmpsheet.APPLICATION
* --- Set Excel to only have one worksheet ---
oExcel.SheetsInNewWorkbook = 1
* --- Delete the Default Workbook that has 3 worksheets ---
oExcel.Workbooks.CLOSE
* --- For DEBUG Purposes - If Not Needed, Set .F. ---
oExcel.VISIBLE = .T. && Might be useful to see operation first time or two
* --- Now Open Desired Excel File ---
oExcel.Workbooks.OPEN(mcExcelFile) && Fully Pathed Excel File Name
oExcel.WINDOWS(mcExcelFName).ACTIVATE && JUSTFNAME portion of mcExcelFile
xlBook = JUSTFNAME(oExcel.ActiveWorkbook.FULLNAME) && oExcel.ActiveWorkbook.FULLNAME
xlSheet = oExcel.activesheet
oExcel.ReferenceStyle = 1 && Ensure Columns in A-B Reference Format
* Select Range of Rows & Columns:
* --- Go To Desired Worksheet within Workbook ---
oExcel.Sheets("Summary").SELECT && In This Case Worksheet Named 'Summary'
xlSheet = oExcel.activesheet
* --- Determine Last Cell At This Point ---
mnLastRow = oExcel.activesheet.UsedRange.ROWS.COUNT
mcLastRow = ALLTRIM(STR(mnLastRow))
mnLastCol = oExcel.activesheet.UsedRange.COLUMNS.COUNT
mcLastCol = ALLTRIM(STR(mnLastCol))
* --- Select Desired Range Example: Range("B6:J15").Select ---
mcFirstCol = "C"
mcFirstRow = "5"
xlSheet.RANGE(mcFirstCol + mcFirstRow + ":" + mcLastCol + mcLastRow).SELECT
* To do the SaveAs:
* --- Save Excel Results ---
oExcel.CutCopyMode = .F. && Clear the clipboard
oExcel.DisplayAlerts = .F.
oExcel.activesheet.SAVEAS(mcOutputFile,11,0) && Fully Pathed DBF File Name
* --- Close the Worksheet ---
oExcel.Workbooks.CLOSE
* --- Quit Excel ---
oExcel.QUIT
RELEASE oExcel, xlSheet