anandvn has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm new to perl and I want to open a word document in the MS-word application with cursor poiting the location specified by me. Is it possible to implement this requirement in Perl. Please help.

Thanks,
Anand V

Replies are listed 'Best First'.
Re: Opening MS-Word Application
by marto (Cardinal) on Sep 28, 2010 at 08:59 UTC

    Use Win32::OLE to automate Word. I'm not sure if you'll be able to use that to move to the mouse to a specified location but Win32::GuiTest could deal with that part.

Re: Opening MS-Word Application
by dasgar (Priest) on Sep 28, 2010 at 11:05 UTC

    I'm not sure I understand why you're wanting to do this or what you mean by 'cursor'. If you're referring to the mouse pointer, then I'd agree with marto that Win32::OLE probably won't do that.

    However, if you're referring to the flashing 'cursor' inside Word that indicates where the next character you type will go, then this might be possible. Basically, the concept would be the following:

    1. Use Win32::OLE to open Word and the desired Word document. Do this with the option to make Word visible.
    2. Issue the Word commands to move the 'cursor' to the desired location within the document.
    3. Have your code exit without closing Word. (Never tried this, so I don't know if this step will work properly or as desired.)

    I'm sure that you would love to have seen code to do this and I would have preferred to give some code too. However, I'm posting this from a system that does not have Word installed and does not have access to any of the code that I have written to interact with Word. If I get a chance later this week, I'll post an update with some syntax for the make visible part and the cursor movement in Word.

Re: Opening MS-Word Application
by locked_user sundialsvc4 (Abbot) on Sep 28, 2010 at 13:29 UTC

    OLE will be “the way that you do this.”   The only question is, does the Word object allow you to designate the cursor-position?

    One possible strategy (if a direct “put cursor here” method isn’t available...) is to “select” some word and then un-select it.   Nevertheless, the only way to be sure of your options is to look at Microsoft’s OLE API specification and see what gifts they deigned to provide.