Hi my friend
To open the Excel WorkBook from you VFP code use..
Code:
oX=CREATEOBJECT("EXCEL.APPLICATION")
oX.WORKBOOKS.OPEN("D:\BOOK1.XLS")
Then you can start Automate your Excel object as you wish
For example you can start update some cells in your workbook like that
Code:
oX.RANGE("A2").SELECT()
oX.ACTIVECELL.FORMULAR1C1 = "MIKEL91"
This will insert your name in the selected cell.
In general keep in mind that the best way to understand the Excel/Word or whatever COM object is to record what you want to do as macro inside this application (Excel for example) after you done, you can select you macro in the edit mode and study the syntax, after some modifications you can copy and paste the syntax to VFP.
*-- Some ideas to modify the generated code from the macro
If you have code like this
Selection.TypeText
Text:="walid"
you have to understand that VBA don't care about the sequence of parameter if you name them in other words
Text can be the parameter number 5 if you need to just send this parameter in VFP you have to use something like that
("","","","","walid"

. In VBA you don't need this extra typing just use Text:="Walid" so you name you parameter name
*I know we can’t do this in VFP so if you got some thing like that highlight the method name (TypeText in this case)
Then press F1 (Make sure you installed the VBA help files they are in your office installation CD) to see the syntax of this function so you can put you parameter in the right position.
*-- In most cases VBA uses a predefined constants in the code generated by the macro and we don't know what is the run time value for this constant.
Well, this is the Intellisense feature of visual basic. but you can do that if you can get all the constants from the object type library file *.OLB to a header file *.H and include it in you application
For example Excle type library file is Excel9.olb and it is located in C:\program files\Microsoft office\office
*-- One way to do that is to use my program to make the conversion for you
Code:
LOCAL lnInFile,lnOutFile,lcText,lcOutText,llOutText
SET DEFA TO GETDIR()
tcInFile = GETFILE()
lnDotPos =RAT('.',tcInFile)
tcOutFile = LEFT(tcInFile,lnDotPos-1)+".h"
CLOS ALL
lnInFile = FOPEN(tcInFile)
lnOutFile = Fcreate(tcOutFile)
lcText = ""
lcOutText = ""
llOutText = .F.
DO WHILE !FEOF(lnInFile)
lcText = FGETS(lnInFile)
IF "}" $ lcText
llOutText = .F.
ENDIF
IF llOutText
lcOutText = ALLT(lcText)
lcOutText = STRT(lcOutText,'=',' ')
lcOutText = "#DEFINE "+ALLT(lcOutText)
IF RIGHT(lcOutText,1)=","
lcOutText=SUBST(lcOutText,1,LEN(lcOutText)-1)
ENDIF
=FPUTS(lnOutFile,ALLT(lcOutText))
ENDIF
IF "ENUM {" $ UPPER(lcText)
llOutText = .T.
ENDIF
ENDDO
CLOS ALL
Rick Strahl has a free class to do that in his web site
I didn't have time yet to play with it but I am 150% sure it will work very well.
If you don't want to go through all of this and you want to know the value if any constant very quickly run your macro in the debug mode, stop with you mouse on top of any constant, a tool tip will display the value of that constant.
One more trick, End With in VB = EndWith (one word)
Hope this will help.
Good luck
Walid Magd
Engwam@Hotmail.com