Thanks alot.
I was able to add the code using .CodeModule.InsertLines method. Works fine!
Much appreciated
Charles Richard
>>I am creating an excel document through automation. I need to add code to the Worksheet_Change event. How can I do this from VFP 7?
>>
>>Recording a macro doesn't follow through to the VBA editor so I can't see how Excel does it)
>>
>
>The piece of the object model you need to examine is VBIDE and its VBComponents collection. I was able to find the code in a Word document with code along these lines:
>
>
> LOCAL loComponent AS VBIDE.VBComponent
>
> WITH THIS.odocument.VBProject
> ************************************************************* * Grab the right module
> ************************************************************* loComponent=.NULL.
> FOR lnComponent = 1 TO .VBComponents.COUNT
> IF UPPER(.VBComponents(lnComponent).NAME) == "THISDOCUMENT"
> loComponent = .VBComponents(lnComponent)
> EXIT
> ENDIF
> ENDFOR
>
> ENDWITH
>
> RETURN loComponent
>
>
>Once you get that far, you want to look at the CodeModule member of the component.
>
>It's pretty brute force, but I was able to replace the code in one document with code from another.
>
>Tamar