I have the following in a loop that is looping through an array created with AFIELDS(). Date and DateTime fields are really the only ones that I've seen cause problems. The special case for characters fields is just to remove and trailing spaces.
lc_Field = "XL_Table." + la_Fields[ ln_Loop, 1 ]
DO CASE
CASE la_Fields[ ln_Loop, 2 ] = "G"
.Cells( ln_CurrentRow, ln_Loop ).VALUE = "*General*"
CASE la_Fields[ ln_Loop, 2 ] = "M"
.Cells( ln_CurrentRow, ln_Loop ).VALUE = STRTRAN( &lc_Field, CHR(13) + CHR(10), CHR(10) )
CASE INLIST( la_Fields[ ln_Loop, 2 ], "D", "T" ) .AND. EMPTY( &lc_Field )
CASE la_Fields[ ln_Loop, 2 ] = "C"
.Cells( ln_CurrentRow, ln_Loop ).VALUE = RTRIM(&lc_Field)
OTHERWISE
.Cells( ln_CurrentRow, ln_Loop ).VALUE = &lc_Field
ENDCASE
>i get a ole error code 0x800a03ae on the below "=&value" statment when the field is a blank date field. obviously i could do a TYPE on the field and figure out if it is a null date, but what other field types and values do i have to do special validation for before doing the oExcel.activecell.value assignment?
>
>lvalue = lcalias + "." + FIELD(lni)
>oExcel.ActiveCell.Value = &lvalue
>
>thanks
>
>brenda
>
>
>>Just do an oExcel.SaveAs("C:\Book3.xls"). Named parameters aren't allowed when doing Automation from FoxPro. The other parameters it put in the macro code appear to be default values, so you shouldn't have pass them. If you need to pass them, then you'll need to find the parameter order and pass them as you would to a function/method call.
>
>>>thanks for the info and code. works well. but now i want to save the workbook as a specific name in a specific folder. went into excel, recorded a macro and then look at the VB code. i added the oExcel. before the ActiveWorkbook.Saveas. but i get a syntax error when i execute it in the command window.
>>>
>>>oExcel = CREATEOBJECT('Excel.Application')
>>>oExcel.workbooks.add
>>>oExcel.ActiveWorkbook.SaveAs FileName:="C:\Book3.xls", FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
>
>
>>>>LOCAL oExcel, lnlast, lcalias, lvalue, lnrow
>>>>oExcel = CREATEOBJECT('Excel.Application')
>>>>* Create a new work sheet
>>>>oExcel.Workbooks.Add
>>>>lcalias = ALIAS()
>>>>lnlast = FCOUNT()
>>>>lnrow = 0
>>>>SCAN
>>>> lnrow = lnrow + 1
>>>> FOR lni = 1 TO lnlast
>>>> lccell = CHR(64 + lni) + TRANSFORM(lnrow)
>>>> oExcel.Range(lccell).Select
>>>> lvalue = lcalias + "." + FIELD(lni)
>>>> oExcel.ActiveCell.Value = &lvalue
>>>> NEXT
>>>>ENDSCAN
>>>>Of course, if you have more than 26 fields, you'll have to make an adjustment >in the column name.
>
>>>>What do you mean by "Automation"? and what is AFAIK?